# Contour based blurring

Suppose I have an image of a cat and a binary mask image corresponding to cat's location as shown

I would like to blur the image region surrounding the cat but as a function of distance from the cat's boundary pixels. Essentially, the further a pixel is away from the boundary, the greater the degree to which it gets blurred. The ideal distance measure would be iso-contours which extend radially from the cat's boundary pixels, but this is possibly complicated. I would settle for Euclidean distance for now.

Any idea how I can accomplish this ?

Compute the distance transform. You can do that very efficiently. This will give you the Euclidean distance to the closest boundary pixel, as well as the index of that pixel. Then, normalize all the distances in the mask so that the maximum becomes 1. This is required for the next stage: At each point initiate a Gaussian kernel. The kernel size $h$ (and similarly the standard deviation $\sigma$) should be a function of the weight, obtained from distance normalization. You can either use a coefficient - linear proportionality - or a complex kernel, depending on the blurring requirements.

Finally, blur the signal at each pixel using the generated mask. Each pixel gets a unique mask and thus a different blurring. Note that, some of the pixels could get the same blur.

You only need to adjust the kernel size $h$, as for typical Gaussian kernels, $\sigma$ is a function of $h$. The function is simply a lookup table:

   $h$  $\sigma$
3    (0.65)
5    (0.87)
7    (1.43)
9    (1.88)
11   (2.31)