Instructions
Requirements and Specifications
Source Code
NEAREST
function gl = nearest(im, i, j)
i = round(i);
j = round(j);
% if j < 1 || j > size(im,2) || i < 1 || i > size(im,1)
% gl = 0;
% else
% gl = im(i,j);
% end
if ~((j<1) || (j>size(im,2)) || (i < 1) || (i > size(im,1)))
gl = im(i,j);
else
gl = 0;
end
end
ROTATE
function im1 = rotateImage(im, n)
% get size of image
[M, N, p] = size(im);
% Calculate the size of the new image
Mnew = round(M*sqrt(2));
Nnew = round(N*sqrt(2));
% Create a matrix of zeris with the new size
im1 = zeros(Mnew, Nnew, p);
% Loop through all points of the image
for i = 1:Mnew
for j = 1:Nnew
% New coordinates clockwise
inew = (i-Mnew/2)*cosd(n) - (j-Nnew/2)*sind(n)+M/2;
jnew = (i-Mnew/2)*sind(n) + (j-Nnew/2)*cosd(n)+N/2;
% Now, set
im1(i,j, :) = nearest(im, inew, jnew);
end
end
im1 = im1/255;
end