0% found this document useful (0 votes)
13 views6 pages

DIP Lab ASSIGMENT 1

This document contains an assignment submitted by Noor-Ul-Ain (21-SE-78) to their professor Mam Nazia for their DIP Lab course. The assignment contains 3 questions related to image processing techniques. Question 1 demonstrates bilinear and bicubic interpolation using MATLAB built-in functions and custom code. Question 2 shows image rotation using linear and bicubic interpolation. Question 3 computes different distance transforms - Euclidean, Cityblock, Chessboard, and Quasi-Euclidean - on a binary image. Code and output are provided for all questions.

Uploaded by

Noor-Ul Ain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

DIP Lab ASSIGMENT 1

This document contains an assignment submitted by Noor-Ul-Ain (21-SE-78) to their professor Mam Nazia for their DIP Lab course. The assignment contains 3 questions related to image processing techniques. Question 1 demonstrates bilinear and bicubic interpolation using MATLAB built-in functions and custom code. Question 2 shows image rotation using linear and bicubic interpolation. Question 3 computes different distance transforms - Euclidean, Cityblock, Chessboard, and Quasi-Euclidean - on a binary image. Code and output are provided for all questions.

Uploaded by

Noor-Ul Ain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

SOFTWARE ENGINEERING DEPARTMENT

ASSIGNMENT NO.1

DIP LAB

SUBMITTED TO:

Mam Nazia

SUBMITTED BY:
Noor-Ul-Ain (21-SE-78)

1
QUESTION NO.1 CODE:
%Bilinear interpolation with MATLAB builtin Function I
= imread('rice.png');
J_bilinear_builtin = imresize(I, 2, 'bilinear');

% Example 2: Bilinear interpolation with Code


Image1 = imread('cameraman.tif');
rows1 = size(Image1, 1);
columns1 = size(Image1, 2);
rows2 = rows1 * 2; columns2 =
columns1 * 2;
Image2_bilinear = zeros(rows2 + 2, columns2 + 2);
cx = columns2 / columns1; cy = rows2 / rows1;

for x = 2:columns2-1
for y = 2:rows2-1
if (mod(x, 2) == 0)
v = round(x / cx);
w = round(y / cy);
Image2_bilinear(y, x) = Image1(w, v);
else
Image2_bilinear(y, x) = -1;
end end end
for x = 2:columns2-1
for y = 2:rows2-1
if (Image2_bilinear(y, x) == -1)
Image2_bilinear(y, x) = (Image2_bilinear(y - 1, x) + Image2_bilinear(y +
1, x) + ...
Image2_bilinear(y, x - 1) + Image2_bilinear(y, x + 1)) / 4;
end end end

% Example 3: Bicubic interpolation with Code


Image2_bicubic = zeros(rows2 + 2, columns2 + 2);

for x = 2:columns2-1
for y = 2:rows2-1
if (mod(x, 2) == 0)
v = round(x / cx);
w = round(y / cy);
Image2_bicubic(y, x) = Image1(w, v);
else
Image2_bicubic(y, x) = -1;
end end end
for x = 2:columns2-1
for y = 2:rows2-1
if (x ~= 1 && x ~= columns2 && y ~= 1 && y ~= rows2)
Image2_bicubic(y, x) = (Image2_bicubic(y - 1, x - 1) + Image2_bicubic(y
- 1, x) + ...
Image2_bicubic(y - 1, x + 1) + Image2_bicubic(y, x - 1) +
Image2_bicubic(y, x + 1) + ...
Image2_bicubic(y + 1, x - 1) + Image2_bicubic(y + 1, x) +
Image2_bicubic(y + 1, x + 1)) / 8;
end end end

Bicubic interpolation with MATLAB builtin Function


J_bicubic_builtin = imresize(I, 2, 'bicubic');

% Display using subplot subplot(2, 2, 1), imshow(J_bicubic_builtin),


title('Bicubic (Code)'); subplot(2, 2, 2), imshow(J_bilinear_builtin),
title('Bilinear (MATLAB)'); subplot(2, 2, 3), imshow(J_bicubic_builtin),
title('Bicubic (MATLAB)'); subplot(2, 2, 4), imagesc(Image2_bilinear),
title('Bilinear (Code)');

2
OUTPUT:

QUESTION NO.2:

CODE:
% Read the image
originalImage = imread('cameraman.tif');

% Set the rotation angle in degrees rotationAngle


= 45;

% Rotate using Linear interpolation rotatedLinear =


imrotate(originalImage, rotationAngle, 'bilinear');

% Rotate using Bicubic interpolation rotatedBicubic =


imrotate(originalImage, rotationAngle, 'bicubic');

% Display the original and rotated images


figure; subplot(2, 2, 1);
imshow(originalImage); title('Original
Image');
subplot(2, 2, 2);
imshow(rotatedLinear);
title('Linear Interpolation');

3
subplot(2, 2, 3);
imshow(rotatedBicubic);
title('Bicubic Interpolation');

OUTPUT:

4
QUESTION NO.3:

CODE:
% Define the binary image
bw = zeros(5, 5); bw(2,
2) = 1; bw(4, 4) = 1;

% Compute the Euclidean distance transform


[D_euclidean, ~] = bwdist(bw, 'euclidean');

% Compute the Cityblock (Manhattan) distance transform


[D_cityblock, ~] = bwdist(bw, 'cityblock');

% Compute the Chessboard distance transform


[D_chessboard, ~] = bwdist(bw, 'chessboard');

% Compute the Quasi-Euclidean distance transform


D_quasi_euclidean = bwdist(bw, 'quasi-euclidean');

% Display the original binary image and distance transform matrices in the same
window figure;

% Original Binary Image


subplot(2, 3, 1); imshow(bw);
title('Original Binary Image');

% Euclidean Distance Transform


subplot(2, 3, 2); imshow(D_euclidean,
[]); title('Euclidean Distance
Transform');

% Cityblock (Manhattan) Distance Transform


subplot(2, 3, 3); imshow(D_cityblock, []);
title('Cityblock (Manhattan) Distance Transform');

% Chessboard Distance Transform


subplot(2, 3, 4); imshow(D_chessboard,
[]); title('Chessboard Distance
Transform');

% Quasi-Euclidean Distance Transform


subplot(2, 3, 5); imshow(D_quasi_euclidean,
[]); title('Quasi-Euclidean Distance
Transform');

5
OUTPUT:

You might also like