Combine two images in MATLAB
Last Updated :
22 Sep, 2021
In this article, we will learn how to combine two images of the same size in MATLAB.
Now, let’s suppose we have been given two colored images of different sizes. One image has the main figure on the left side and the other has one on the right side. We need to combine the two images such that both figures appear on them.
We need to combine them.
Step 1: Make left half of right_side_image 0 intensity image(black). Also, make right half of left_side_image 0 intensity region.
Syntax:
image_var = imread(” image path here “);
var_name = rgb2gray (image_var);
size( image_var )
imshow( var_name , [ ]);
or
imtool( var_name, [ ]);
Access half columns :
image_var( :, 1:150);
Example I:
Matlab
left=imread( "logo_left.png" );
right=imread( "logo_right.png" );
left=rgb2gray(left);
right=rgb2gray(right);
imtool(left, []);
imtool(right, []);
size(left)
size(right)
left(:, 150:300)=0;
right(:, 1:150)=0;
imtool(left, []);
imtool(right, []);
|
Output:
- In the above program first, we read the left and right images.
- Converted the colored images into grayscale images.
- Displayed the images.
- Displayed the sizes of both images.
- Converted other half intensity as 0. made half part dark.
- Displayed modified images.
Step 2: Combine the left and right parts.
Syntax:
new_image = image_1 + image_2
// condition: both images must be of same size and type.
Example II:
Matlab
left=imread( "logo_left.png" );
right=imread( "logo_right.png" );
left=rgb2gray(left);
right=rgb2gray(right);
imtool(left, []);
imtool(right, []);
size(left)
size(right)
left(:, 150:300)=0;
right(:, 1:150)=0;
imtool(left, []);
imtool(right, []);
combined=uint8(left+right);
imtool(combined,[]);
|
Output:
The output image is the combination of two images.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...