How to overlay a binary mask over an rgb image?

4 ビュー (過去 30 日間)
Hadi Ghahremannezhad
Hadi Ghahremannezhad 2020 年 1 月 9 日
I am trying to overlay a binary mask over an RGB color image. I want to change the white area of the mask to a transparent red area and put it over an rgb image.
For example:
image: diplo000000-L.png mask: sdfsd.png
I want something similar to this:
Untitled.png
I alredy tried this method but I couldn't figure it out. What is a simple way (no matter how slow) to do this?
  1 件のコメント
Turlough Hughes
Turlough Hughes 2020 年 1 月 9 日
What size is your mask and original image?

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

採用された回答

Meg Noah
Meg Noah 2020 年 1 月 9 日
Here's some code:
img = imread('diplo000000-L.png');
mask = imread('sdfsd.png');
mask(:,:,1) = 0;
img(mask>0) = 0;
image(img)
set(gca,'ydir','reverse');
imwrite(img,'newimage.png');
newimage.png
  2 件のコメント
Andrew Soltisz
Andrew Soltisz 2021 年 2 月 23 日
img(mask>0) = 0; is equivalent to img(mask) = 0;
Hadi Ghahremannezhad
Hadi Ghahremannezhad 2021 年 2 月 24 日
Thank you. That's a good point.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by