0
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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.

| improve this answer | |
$\endgroup$
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$

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.