4
$\begingroup$

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

enter image description here

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:

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

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
$\endgroup$
2
  • $\begingroup$ Thanks. This is equivalent to blurring both image layer and alpha mask layer, right? $\endgroup$
    – Libor
    Dec 31, 2012 at 0:08
  • $\begingroup$ 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. $\endgroup$ Dec 31, 2012 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.