import torch


def central_grady(image):
    """Compute central vertical gradient.

    Assumes input is a 4D tensor with dimensions (batch, channels, rows, cols).
    """
    assert(len(image.shape) == 4)
    padder = torch.nn.ReplicationPad2d((0, 0, 1, 1))
    padded_image = padder(image)
    gy = 0.5 * (padded_image[:, :, 2:, :] - padded_image[:, :, :-2, :])
    return gy