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.
Combining the images can be done easily using concatenation:
image3 = [image1 image2]; %# Concatenate horizontally
And you can then visualize image3
using any of the functions IMAGE, IMAGESC, or IMSHOW:
image(image3); %# Display the image in a figure window
NOTE:
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).
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
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
And now you can view image3
as described above.
If you just want to view the two images side by side, you can display multiple images (or graphs) in the same figure using subplot
.