First time here? Check out the FAQ!

Ask Your Question
1

Applying filter with a Mask

asked Jul 21 '17

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Oct 10 '19

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.

Preview: (hide)

Comments

1

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

holger gravatar imageholger (Oct 11 '19)edit

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

holger gravatar imageholger (Oct 11 '19)edit

Question Tools

1 follower

Stats

Asked: Jul 21 '17

Seen: 1,308 times

Last updated: Oct 10 '19