import torch


def blur_with_zeros(image, blur):
    """Blur an image ignoring zeros.
    """
    # Create binary weight image with 1s where valid data exists.
    mask = torch.ones(image.shape, device=image.device)
    mask[image <= 0] = 0

    # Compute blurred image that ignores zeros using ratio of blurred images.
    blurred = blur(image)
    weights = blur(mask)

    blurred[weights == 0] = 0
    weights[weights == 0] = 1
    blurred = blurred / weights

    return blurred