Ask Your Question

Applying filter with a Mask

asked 2017-07-20 21:39:37 -0600

arqam gravatar image

I have an image and a mask, where I want to do filter/blur operations only at the region where the mask is white i.e the mask has value 255 and not where mask has 0.

I tried using these operation :

erode(maskImage,maskImage,Mat()); // values near irrelevant pixels should not be changed
bluredImage = sourceImage + ((bluredImage-sourceImage) & maskImage);

But the & operation cannot be performed in images with different channels.

And when I tried with the accepted answer from here it gave me completely black image.

So how can I do operations with a mask as a parameter?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-10-10 09:52:14 -0600

Jorge Diaz gravatar image

You are trying to apply this with multiple channels which is as easy as splitting the image into the different channel until you have matrixes of the same size ( for instance in RGB, you divide in 3 channels) and then you perform the operation for each channel.

edit flag offensive delete link more



Try Mat::split (as suggested above) followed by your code.

holger gravatar imageholger ( 2019-10-10 19:47:46 -0600 )edit

and mark the question as solved with the answer accepted if this works for you :-)

holger gravatar imageholger ( 2019-10-11 11:58:45 -0600 )edit

Question Tools

1 follower


Asked: 2017-07-20 21:39:37 -0600

Seen: 1,212 times

Last updated: Oct 10 '19