Overlay two images in MATLAB

I want to overlay two images of the same size in matlab. I tried to use the imfuse function, but the image I received was not what I wanted.

The first image is negative for the image obtained after applying the Canny edge detector to my original image. I want to overlay this negative image with black edges on my original image.

Can someone suggest some other function or method for overlaying two images? Thanks and respect.

+4
source share
3 answers

You can use the 'AlphaData' property for the second image:

 >> imshow( origImg ); hold on; >> h = imagesc( edgeImg ); % show the edge image >> set( h, 'AlphaData', .5 ); % .5 transparency >> colormap gray 
+5
source

Try this to overlay two images.

 figure,imshowpair(originalImage,edgeImage); 

This will give you one number, which is a combination of the two. Imshowpair has additional options such as blend, diff, montage. Try them too.

+5
source

I found something, I thought I should share here.

Like Shai and Steve , mentioned using AlphaData images, gives a very good result in many cases. However, if you need to save the image with the original resolution (and without using getframe , print , saveas , etc.), the following will 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's the use of 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 same look as above, but in one matrix (which I could not achieve with 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 this helps someone!

+2
source

Source: https://habr.com/ru/post/1501156/


All Articles