# Blurring Non-Uniform Areas

I have an image with arbitrary area (the boundary is shown in gray):

I would like to blur just the image within boundaries.

Ordinary blur causes the background proliferating to image and vice versa. This results in dark areas near boundaries of the image:

-

One simple solution would be to create a binary (0/255) mask of the area you want to blur. Then blur the source image BITWISE AND mask, blur the mask with the same filter and divide them. As pseudocode:

(filter(source & mask) / filter(mask)) & mask

-
Thanks. This is equivalent to blurring both image layer and alpha mask layer, right? –  Libor Dec 31 '12 at 0:08
I see it as a filter that only averages over the area inside the mask. But yes, you can also see it as blurring a premultilpied alpha image, then convert back to normal RGBA. –  nikie Dec 31 '12 at 9:17