1

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?

avinash k
  • 25
  • 4

1 Answers1

1

This should be your solution,

mat_new=mat_rgb.*mat_binary

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

Pranav Totala
  • 148
  • 2
  • 14
  • 3
    This will work with newer versions of MATLAB. For older versions, you'll need to use `bsxfun` to match the MxNx3 image and MxN mask image. – Cris Luengo Feb 11 '18 at 16:37
  • 1
    Thank you for the answer. I would like add a bit to the question. How could I know how much pixels are removed while performing the masking? – avinash k Feb 17 '18 at 11:56
  • the total number of masked pixel should be `MxN - sum(mat_binary((:,:))` Because number of masking = number of zeros , which i calculated. – Pranav Totala Feb 17 '18 at 15:52