m0j1
m0j1

Reputation: 4267

Removing parts of the image with OpenCV

I have an image and I want to simply remove(or mask) parts of it with OpenCV. this is my original image :

enter image description here

And I want to remove a circle on its center via this image mask :

enter image description here

I use this command in my code which from the tutorials I read should work and black out a circle in the center of my original image :

img = cv2.bitwise_not(imgOriginal,imgOriginal,mask=imgMask)

but the result I get is the image below, in fact instead of removing the masked parts, it just inverts blacks and whites:

enter image description here


I'll appreciate if you can help me on finding a way to properly mask(or remove) the parts I want.
Thanks

Upvotes: 2

Views: 5958

Answers (2)

Andrey  Smorodov
Andrey Smorodov

Reputation: 10852

Try to set pixels to the background color using a mask, like this:

img.setTo(Scalar::all(0),mask);

Upvotes: 1

zindarod
zindarod

Reputation: 6468

Try this:

//given source, mask and destination Mat images with same size
cv::subtract(img, mask, dst);

enter image description here

Upvotes: 1

Related Questions