如何在一个matlab窗口上合并两个图像? [英] how to combine two images on one window matlab?

查看:1711
本文介绍了如何在一个matlab窗口上合并两个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个尺寸为image1 = 250x250和image2 = 250x550的图像. 我想要一张显示这两个图像相结合的图像. 例如image3 = image1 + image2表示image3 = 250x800.

i have two images of size lets say image1=250x250 and image2=250x550. i want to have an image that shows these two images combine. like image3=image1+image2 means image3=250x800.

推荐答案

使用然后您可以使用任何功能 IMAGE 可视化image3 a>, IMAGESC

And you can then visualize image3 using any of the functions IMAGE, IMAGESC, or IMSHOW:

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


注意:

您没有提及要处理的图像类型,只是它们是像素数据的二维矩阵.这意味着它们可能是二进制图像(带有像素值0或1),灰度图像(像素值代表从黑色到白色的范围),或

You didn't mention what type of images you are dealing with, only that they are 2-dimensional matrices of pixel data. This means they could be binary images (with pixel values of 0 or 1), grayscale images (with pixel values that represent a range from black to white), or indexed color images (with pixel values that represent indices into a colormap).

对于二进制和灰度图像,上述解决方案应该可以正常工作.但是,如果每个彩色图像都有自己独特的 colormap .如果使用功能 IMREAD 从文件中加载图像,则可以得到这样的颜色图:

For binary and grayscale images, the above solution should work fine. However, indexed color images could be trickier to combine if each image has its own unique colormap. If the image is loaded from a file using the function IMREAD, you can get the color map like so:

[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包含不同的颜色排列,那么就不能很容易地将两个图像组合在一起.一种解决方案是首先将图像转换为3维使用功能 IND2RGB 的真彩色图像,然后使用函数 CAT :

Now, if map1 and map2 contain different arrangements of colors, the two images can't be so easily combined. One solution would be to first convert the images to 3-dimensional truecolor images using the function IND2RGB, then combine them using the function 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.

And now you can view image3 as described above.

这篇关于如何在一个matlab窗口上合并两个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆