Hello all, this is the definition of total variation loss

Screenshot from 2019-09-09 17-40-05.png1959×282 37.1 KB

So, I implemented it as follows:
    def compute_total_variation_loss(img, weight):      
        tv_h = ((img[:,:,1:,:] - img[:,:,:-1,:]).pow(2)).sum()
        tv_w = ((img[:,:,:,1:] - img[:,:,:,:-1]).pow(2)).sum()    
        return weight * (tv_h + tv_w)


Is it correct? What does it means img[:,:,1:,:] - img[:,:,:-1,:]?