I found something, I thought I should share here.
As Shai and Steve mentioned using AlphaData
of an image gives a very nice result in many cases. However if you need to save the image with the original resolution (and not using getframe
, print
, saveas
, etc), the following would help.
(I use the second example in Steve's article)
% Reading images
E = imread('http://www.mathworks.com/cmsimages/63755_wm_91790v00_nn09_tips_fig3_w.jpg');
I = imread('http://www.mathworks.com/cmsimages/63756_wm_91790v00_nn09_tips_fig4_w.jpg');
% normalizing images
E = double(E(:,:,1))./double(max(E(:)));
I = double(I(:,:,1))./double(max(I(:)));
Here is overlaying using AlphaData
(Opacity):
figure, imshow(E), hold on
red = cat(3, ones(size(E)), zeros(size(E)), zeros(size(E)));
h = imshow(red);
set(h, 'AlphaData', I);
To get the exact same appearance as above but in one matrix (which I could not achieve using imfuse
), you can use this simple code:
Comb = E;
Comb(:,:,1) = (1-I).*E + I; % red
Comb(:,:,2) = (1-I).*E; % green
Comb(:,:,3) = (1-I).*E; % blue
figure, imshow(Comb)
Hope it helps someone!