MATLAB: I am trying enlarge an image using interpolation without using MATLAB commands, but the image isn’t resizing properly.

image processing

This function interpolates the rows first and then the columns from the interpolated rows.
function [enl] = enlarge(image)
img = imread(image);
img = double(img);
[m,n] = size(img);
% enl = zeros(m,n);
for i = 1:1:m
for j = 1:2:n-1
enl(i,j+1) = (img(i,j)+img(i,j+1))/2;
end
end
for i = 1:2:m-1
for j = 1:1:n
enl(i+1,j) = (img(i,j)+img(i+1,j))/2;
end
end
imshow(enl)
imwrite(enl, 'enl.gif')
end

Best Answer

You are interpolating in one direction, but then you are ignoring the results of that when you interpolate in the other direction. Both times you overwrite the matrix en1 with values computed solely from img.