2010-10-27 123 views

回答

12

组合图像可以很容易地使用concatenation来完成:

image3 = [image1 image2]; %# Concatenate horizontally 

然后你就可以使用任何功能IMAGEIMAGESC,或IMSHOW可视化image3

image(image3); %# Display the image in a figure window 


注意:

你没有提及你正在处理的图像类型,只是它们是像素数据的二维矩阵。这意味着它们可以是binary images(具有0或1的像素值),grayscale images(具有表示从黑到白的范围的像素值)或indexed color images(具有表示指数到色图中的像素值)。

对于二进制和灰度图像,上述解决方案应该可以正常工作。但是,如果每张图像都有自己独特的colormap,索引的彩色图像可能会更加复杂。如果图像从一个文件中使用函数IMREAD加载,你可以得到的彩色地图,像这样:现在

[image1,map1] = imread('image1.png'); %# Image and colormap for image file 1 
[image2,map2] = imread('image2.png'); %# Image and colormap for image file 2 

,如果map1map2包含的颜色不同的安排,两个图像不能这么容易结合。一个解决办法是首先将图像转换为使用功能IND2RGB 3维truecolor images,然后使用功能CAT结合他们:

image1 = ind2rgb(image1,map1); %# Convert image 1 to RGB 
image2 = ind2rgb(image2,map2); %# Convert image 2 to RGB 
image3 = cat(2,image1,image2); %# Concatenate the images along dimension 2 

并且如上所述,现在你可以查看image3

+0

CAT参数尺寸不一致............“为什么我在连接时出现此错误” – chee 2010-11-27 15:42:20

+0

@chee:这意味着您的图像没有相同的行数或您可能会尝试将二维图像与三维图像连接起来。 – gnovice 2010-11-27 18:03:29

+0

bt wt如果我想以任何方式加入它们? – chee 2010-11-30 16:45:11

1

如果您只是想并排查看这两幅图像,则可以使用subplot在同一幅图中显示多幅图像(或图形)。

相关问题