Hi,
Following code illustrates the interpolation using filter2 and fspecial
clear
close all
clc
foto=imread('office_3.jpg'); and
filter_coef= fspecial('average',[3 3]);
Y=interp(foto,filter_coef);
imshow(Y);
function Y = interp(A, filter_coef)
if (length(size(A)) == 3)
for i=1:3
Y(:,:,i) = interp(A(:,:,i),filter_coef);
end
else
[m,n] = size(A);
A_ = []; Y = [];
% columns interpolation
A_col= filter2(filter_coef,A);
for i=1:n
A_ = [A_ A(:,i) A_col(:,i)];
end
A_(:,end) = [];
% rows interpolation
A_rows = filter2(filter_coef,A_')';
for i=1:m
Y = [Y; A_(i,:); A_rows(i,:)];
end
Y(end,:) = [];
end
end
Output: