Search code examples
imagematlabimage-processingmaskingimage-masking

Masking an RGB image with Binary mask Code in matlab


I have a RgB image (MxNx3) and binary mask which is a image consisting of 0's and 1's. Anywhere that the mask is 0, I wish to make exactly 0 in the original image, while anywhere the mask is 1 I just want to leave alone. Any solutions on how to proceed to achieve the desired results?


Solution

  • This should be your solution,

    mat_new=mat_rgb.*mat_binary
    

    . (dot) before a operator will make element wise operation on the matrices.