Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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