Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. This problem investigates nearest neighbor and bilinear interpolation. For si

ID: 3870505 • Letter: 1

Question

1. This problem investigates nearest neighbor and bilinear interpolation. For simplicity, we will focus on estimating the image intensity at a single location. Interpolation is used when transforming an image through resizing, rotating, etc. in which case, the image intensity will need to be estimated at a number of locations Consider the diagram below of four pixels 2 where the dots () represent the locations where we know the image intensity and the × represents the location where we would like to estimate the image intensity. By convention, the vertical axis is the x-axis and the horizontal axis is the y-axis. Suppose the four pixels are at the following locations (indicated by (xy)) and have the following intensity values (indicated by p) (x1,y1)= (4,10) (X2,y2) = (4,11) (x3Js) = (5,10) (x4.34)= (5,11) p1=100 p2-107 p3-120 p4-130 and that we would like to estimate the image intensity at a fifth location (x5,Ys) = (4.3, 10.4) That is, we want to estimate ps a) Provide an estimate for ps using nearest neighbor interpolation.

Explanation / Answer

% scale up using interpolation

img = imread('t1.gif');

prompt = 'Enter the scale up value ';

zoom_scale = input(prompt);

a = size(img);

x = a(:,1);

y = a(:,2);

%z = a(:,3);

for i = 1:zoom_scale*x

xx = i/zoom_scale;

x1 = max(1,floor(xx));

x2 = ceil(xx);

x_int = rem(xx,1);

for j = 1:zoom_scale*y

yy = j/zoom_scale;

y1 = max(1,floor(yy));

y2 = ceil(yy);

y_int = rem(yy,1);

BL = img(x1,y1,:);

TL = img(x1,y2,:);

BR = img(x2,y1,:);

TR = img(x2,y2,:);

R1 = BR*y_int+BL*(1-y_int);

R2 = TR*y_int+TL*(1-y_int);

res_img(i,j,:) = R1*x_int+R2*(1-x_int);

end

end

I = mat2gray(res_img);

imshow(I);