I am new to image processing and I am interested how image masking can be used to extract a portion of a image.

Have a look at this OpenCV tutorial.

In the section Application of Mask, they say that you can use a white mask over the area of the image you want to extract.

So I am interested in how this math works. Correct me if I am wrong but if I take the minimum of the pixel from the original pixel and the mask I should get the portion of the portion of the image I want to extract.

This works because the area that I want to extract is covered by the white area of the mask, ie covered by pixels with 255 in all channels, so

min(pixel, 255) 

will always give me the pixel value,

while on the other hand the portions I don't want are covered by black pixels(intensity value of 0), so

min(pixel, 0)

will always give me 0 thus I will exclude these sections from my filter.

This my intuition correct ? Is this how image masking works in order to extract the image ?


You may interpret it this way, but this yields a limited interpretation, because for instance the image may have a maximum different from $255$. I consider masking as a product operation. For a binary mask, the values are $0$ and $1$. Thus if $p$ denotes one pixel value, you get $0\times p = 0$ outside the mask, and $1\times p = p$ inside.

This way, you do not depend on the range of the image anymore. The product can be interpret as the binary AND operation, as you can see in Image masks. The relation between min, max and products could be understood in the more global framework of lattices and Boolean algebras, which are useful in mathematical morphology, and help you define other types of useful masks.

For more continuous operations on "real-valued" images, you can use masks with values in $[0,1]$, whose product with the image allows dimming between white and black mask areas, using intermediate values. For instance in the following, the mask masks the left part of an image (black mask values), keep the right part, and affects attenuated values (smooth transition) in the central part.

grayscale mask

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.