Image Zooming in MATLAB
Last Updated :
13 Oct, 2022
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can also zoom in on an image. Following are the steps to the same.
Example 1:
Matlab
imageVar = imread( 'SampleImage.png' );
[m,n] = size(imageVar);
z = 4;
for i = 1:m
for j = 1:n
for k = 1:z
zoomedImage((i-1)*z+k,(j-1)*z+k) = imageVar(i,j);
end
end
end
imshow(imageVar), title( 'Original' );
figure, imshow(zoomedImage), title( 'Zoomed' )
|
Output:
Example 2:
Matlab
imageVar = imread( 'gfglogo.png' );
[m,n] = size(imageVar);
z = 9;
for i = 1:m
for j = 1:n
for k = 1:z
zoomedImage((i-1)*z+k,(j-1)*z+k) = imageVar(i,j);
end
end
end
imshow(imageVar), title( 'Original' );
figure, imshow(zoomedImage), title( 'Zoomed' )
|
Output:
Explanation:
- Read the image file using imread command.
- Set the original dimensions of the image as m and n.
- To set new dimensions, set the value of the zooming factor. Here zooming factor is denoted by variable z.
- Now we’ll use Pixel Replication to zoom in on the image. Pixel Replication is the process of increasing pixels in an image. In this process, we do not add any more detail to the image. In this step, we use three nested for loops to change the dimension of the image for a zoom-in purpose.
- In this step, we’ll show the original image with the title ‘Original’.
- In this step, we’ll show the zoomed-in image with the title ‘Zoomed’.
Note: After zooming, since we are adding more pixels (pixel replication) the picture quality decreases.
Share your thoughts in the comments
Please Login to comment...