Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Uttara University

Lab Assignment 2
Course Title: Computer Vission and image processing and sessional
Course Code: CSEC467

Submitted To:
Name: Md.Harun-Ar-Rashid
Lecturer
Department of Computer Science & Engineering
Uttara University
Submitted by:
Name: Nabila Nowshin
ID: 2201081072
Batch: 50 B
Department of Computer
Science
& Engineering
Uttara University
Submission Date:05/03/2023
Pixel Replication or(Nearest Neighbour interpolation) Code:

clc; [clear the command window] clear all;


[clears all variables in the workspace ] close
all; [close all open Figure ]

img = imread('elham.jpg'); [reads in the image 'elham.jpg' and


stores it in the variable img]

% Check the number of dimensions of the input image


if ndims(img) == 3
[m,n,~] = size(img);
else
[m,n] = size(img); end

Z = input('Enter the Zooming Factor = ');

% Initialize the output image with zeros


A = zeros(m*Z, n*Z, 'uint8'); [initializes a new image matrix with
zeros, scaled by the zooming factor, with data type 'uint8']

for i = 1:m [1st dimension of input img where it is going to extract


each and every row of the img]
for j = 1:n [next input of dimension img that extract each and every
coloum of the img]
for k = 1:Z [ loops through each zoomed-in pixel in the new
image]
A((i-1)*Z+k,(j-1)*Z+k) = img(i,j); [assigns the value of the
original pixel to the corresponding zoomed-in pixel] end
end end

% Display the images


imshow(img),title('Original Image'); [displays the original image with
a title] figure; [creats a figure ]
imshow(A),title(sprintf('Zoomed Image (Zooming Factor = %g)', Z));
[displays the zoomed image with a title that includes the zooming
factor]

You might also like