简体   繁体   English

在MATLAB中叠加两个图像

[英]Superimpose two images in MATLAB

I want to superimpose two images of same dimensions in matlab. 我想在matlab中叠加两个相同尺寸的图像。 I tried to use imfuse function but the image I got was not the same as I wanted. 我尝试使用imfuse函数,但我得到的图像与我想要的不一样。

The first image is the negative of the image obtained after applying Canny edge detector to my original image. 第一张图像是将Canny边缘检测器应用于原始图像后获得的图像的负片。 I want to impose this negative image with black edges onto my original image. 我想将带有黑色边缘的负片图像强加到原始图像上。

Can someone suggest some other function or method for superimposition of two images ?? 有人可以建议一些其他功能或方法叠加两个图像?? Thanks and Regards. 谢谢并恭祝安康。

Try this to superimpose two images. 试试这个以叠加两个图像。

figure,imshowpair(originalImage,edgeImage);

This will give you a single figure which is a combination of the two. 这将给你一个单独的数字,这是两者的组合。 imshowpair has some additional options like blend,diff,montage. imshowpair有一些额外的选项,如混合,差异,蒙太奇。 Try them too. 也试试吧。

You may use the 'AlphaData' property of the second image: 您可以使用第二个图像的'AlphaData'属性:

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

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. 正如ShaiSteve提到的,在许多情况下使用图像的AlphaData会得到非常好的结果。 However if you need to save the image with the original resolution (and not using getframe , print , saveas , etc), the following would help. 但是,如果您需要使用原始分辨率保存图像(并且不使用getframeprintsaveas等),以下内容将有所帮助。

(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): 这里使用AlphaData (不透明度)重叠:

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: 要获得与上面完全相同的外观,但在一个矩阵中(我无法使用imfuse实现),您可以使用这个简单的代码:

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! 希望它可以帮到某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM