MATLAB: Interpolation Nearest Neighbor

image interpolation neighborImage Processing Toolbox

Please, I need help to understand why appears the lines on my interpolation.
the code is:
clear imagem2;
clc;
imagem1=imread('olho.tif');
fator=1.5;
[lin,col,d]=size(imagem1);
for i=1:lin
for j=1:col
%mapeando e interpolando os pixels da imagem original para uma nova matriz.
imagem2(round(1+(i-1)*fator),round(1+(j-1)*fator),:)=imagem1(i,j,:);
end
end
figure(1)
imshow(imagem1)
title('Imagem Original')
figure(2)
imshow(imagem2)
title('Imagem Interpolada')
imwrite(imagem2,'imagem2.jpg');
Thanks for your help.

Best Answer

The description of your problem is very lean. Posting a copy of the resulting image would be a good idea.
Please try this:
factor = 1.5;
for j = 1:4
disp(round(1+(j-1)*fator));
end
% Result: 1 3 4 6
This means, that e.g. the 2nd row and column of the created image do not get any value and have therefore the value 0. A solution would be to run the loopover the coordinates of the output image and divide the coordinates of the input image by "factor". The speed will be dramatically higher, if you pre-allocate the output arry:
imagem2 = zeros(round(lin*factor), round(col*factor), 3)
But much more efficient is using INTERP2 or IMRESIZE.
Related Question