Ask Your Question
1

Applying filter with a Mask

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

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
blur(sourceImage,bluredImage,Size(3,3));
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 http://answers.opencv.org/question/30... 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
1

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

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

Comments

1

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

holger gravatar imageholger ( 2019-10-10 19:47:46 -0500 )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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 622 times

Last updated: Oct 10