Interpolation Nearest Neighbor
18 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Jan
2011-4-11
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.
2 个评论
Abuzar Ahsan
2013-3-3
This is not the correct way for the coding of nearest neighbor interpolation.I found the error when I tested it for 47 by 27 image.Up till now you have just succeeded in packing the given image in a required dimension which when ever is zoomed in,shows what basically you are going to do.Now what you are to do ,is to find out the minimum distance between pixels and then assign the intensity value at that index to the point of interest.Which when I did,took too much time even for smaller images.So try to find out the strategy which exactly solve the problem I have pointed out......
Image Analyst
2013-3-3
编辑:Image Analyst
2013-3-3
Who are you responding to in this 2 year old post? Jan or Leandro? If it's Leandro, you should have posted this as an answer. But like Jan said, the best way to do it is:
enlargedImage = imresize(imagem1, int32([lin*fator, col*fator]), 'nearest');
so I'll mark Jan's answer as the solution, since the original poster never did.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!