How to overlay a binary mask over an rgb image?
27 views (last 30 days)
Show older comments
Hadi Ghahremannezhad
on 9 Jan 2020
Commented: Hadi Ghahremannezhad
on 24 Feb 2021
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:
mask:
![diplo000000-L.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260993/diplo000000-L.png)
![sdfsd.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260994/sdfsd.png)
I want something similar to this:
![Untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260995/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 Comment
Accepted Answer
Meg Noah
on 9 Jan 2020
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261000/newimage.png)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!