Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

% Reads the image "rice.

png" and stores it in the variable x


x=imread('rice.png');
% Sets up a subplot layout with 3 rows and 1 column. This line activates the
%first subplot
subplot(3,1,1)
% Displays the image x using the imshow function
imshow(x)
%Adds a title "First Image" to the current subplot
title('First Image')
% Gets the size (dimensions) of the image x and stores it in the variable d
d=size(x);
% Reads the image "moon.tif" and stores it in y
y=imread('moon.tif');
%Resizes image y to match the dimensions of x using imresize
y=imresize(y,[d(1) d(2)]);
%Sets up a subplot layout with 3 rows and 1 column. This line activates the
%second subplot
subplot(3,1,2)
%Displays the resized image y using the imshow function
imshow(y)
%Adds a title "Second Image" to the current subplot
title('Second Image')
% Loops through each pixel of both images (x and y) and adds the
%corresponding pixel values together. The sum is stored in the
%corresponding location of the z variable.
for i=1:d(1);
for j=1:d(2);
z(i,j)=(x(i,j)+y(i,j));
end
end
%Sets up a subplot layout with 3 rows and 1 column. This line activates the third subplot
%subplot(3,1,3)
%: Displays the combined image z using the imshow function
imshow(z)
%Adds a title "Result Image" to the current subplot
title('Result Image')

Result discussion:
Brighter overall: Because the code adds the corresponding pixel values from each image,
the resulting image will likely be brighter than the originals. Areas where both images have
high-intensity values will be even brighter in the combined image. For instance, the areas
of the rice with the most highlights might appear very bright.

You might also like