フィルターのクリア

How to overlay a mask on an image with zero transperancy?

1 回表示 (過去 30 日間)
Tawsif Mostafiz
Tawsif Mostafiz 2022 年 3 月 6 日
編集済み: DGM 2022 年 3 月 6 日
I am trying to overly this mask:
Onto this bw image:
Using this code:
maskedRgbImage1 = bsxfun(@times, bw, cast(mask, 'like', bw));
The output is like this:
But I want the red mask to completely overlap the black part, like this:
How can I do that?
  1 件のコメント
Simon Chan
Simon Chan 2022 年 3 月 6 日
You may use function imoverlay.
Notice that the size of the attached images are not the same.

サインインしてコメントする。

採用された回答

DGM
DGM 2022 年 3 月 6 日
編集済み: DGM 2022 年 3 月 6 日
You can still use basic masking methods. Note that in this case, the images as supplied are both uint8. If your working images are logical class, you might need to deal with making sure they're compatible with arithmetic operations with images of integer numeric class. They're also mismatched in size by a few pixels. I'm assuming that's just an issue with the way the images were saved; otherwise, you'll have to figure out how to fix the size mismatch. I just elected to crop off the difference.
RB = imread('redblob.png');
BB = imread('blackblob.png');
RB = RB(6:end,:,:); % they aren't the same size
% use logical masking
mask = repmat(any(RB<255,3),[1 1 3]); % create a mask where the red blob is
outpict1 = BB;
outpict1(mask) = RB(mask); % compose
imshow(outpict1)
% use multiplicative composition
mask = repmat(uint8(any(RB<255,3)),[1 1 3]); % create a mask where the red blob is
outpict2 = RB.*mask + BB.*(1-mask); % compose
imshow(outpict2)

その他の回答 (0 件)

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by