MATLAB logical image uint8 image multiplication

I have two images. 1st one is with data type uint8. 2nd one with data type logical. I want to multiply these two images so that I can replace the "1" values of 2nd image by the intensity values of 1st image. How can I do that?

Upvotes: 0

Views: 1811

Answers (2)

zeeMonkeez
zeeMonkeez

Reputation: 5177

I'm going to call the image img and the logical matrix mask and assume same size. Using logical indexing you can do

img(~mask) = 0;

which should be faster than multiplication.

Upvotes: 2

flawr
flawr

Reputation: 11628

I assume both images have the same size.

Then you can just do a element-wise multiplication .*, but you obviously first have to conver to the same type, so that would result in following code:

uint8_image .* uint8(logical_image)

Upvotes: 0

Related Questions