Open In App

Image Zooming in MATLAB

Last Updated : 13 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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




% MATLAB program for Zoom image
% read image
imageVar = imread('SampleImage.png');
  
%read image size
[m,n] = size(imageVar);
  
% zooming factor
z = 4;
  
% Pixel replication using nested for loops
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
  
% showing original image with title original
imshow(imageVar), title('Original');
  
% showing zoomed image in another figure with title zoomed
figure, imshow(zoomedImage), title('Zoomed')


Output:

 

Example 2:

Matlab




% MATLAB code for zooming
% read image
imageVar = imread('gfglogo.png');
  
%read image size
[m,n] = size(imageVar);
  
% zooming factor
z = 9;
  
% Pixel replication using nested for loops
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
  
% showing original image with title original
imshow(imageVar), title('Original');
  
% showing zoomed image in another figure with title zoomed
figure, imshow(zoomedImage), title('Zoomed')


Output:

 

Explanation:

  1. Read the image file using imread command.
  2. Set the original dimensions of the image as m and n.
  3. To set new dimensions, set the value of the zooming factor. Here zooming factor is denoted by variable z.
  4. 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.
  5. In this step, we’ll show the original image with the title ‘Original’.
  6. 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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads