Ask Your Question

Revision history [back]

Once you know the mask, which is actually a set of 0 - 1 values, you can just multiply each layer of your color RGB image or the grayscale layer with the binary mask, resulting in 0 values for the actual regions you remove. Its plain and simple :)

EXAMPLE

Grayscale image Mat is represented by (random values between 0 & 255). Mask is defined by a set of 0 and 1 values. Result is the image without the blob region.

1 2 3 4 5   x   0 0 0 0 0   =  0 0 0 0 0
2 3 4 5 6       0 0 0 0 0      0 0 0 0 0
3 4 5 6 7       0 1 1 1 0      0 4 5 6 0
5 6 7 8 8       0 1 1 1 0      0 6 7 8 0
1 1 1 1 1       0 0 1 0 0      0 0 1 0 0

Hope this makes it more clear. Be aware to use a dot wise (element wise) multiplication of both matrices!