# Image Processing in MATLAB

We try to multiplication operation of a black & white image with RGB image in same image but their class is not same: BW -> logical, RGB -> UINT8.

How can I convert from Logical to UNIT*? Or, can we do images which is in different class multiplication?

The simplest way to convert type is: a=uint8(a) where a is your bw image.

I can convert to any type in this way e.g a=double(a).

For multiplication remember to use .* for element wise multiplication. * does matrix multiplication.

I guess you have a Binary (Logic) mask you want to multiply the image by.

It is easy:

mMask = double(mMaskBinary);

for ii = 1:numChannels

mOutImage(:, :, ii) = mMask  .* mInputImage(:, :, ii);

end


In the latest MATLAB releases (From R2016b) expansion is done implicitly.
Hence if you want to do a multiplication between $$M \times N$$ image to $$M \times N \times 3$$ image you can just multiply them element by element and the expansion to the 3rd dimension will happen automatically like in the loop above.

Enjoy.