manual bilinear and nearest neighbor interpolation
8 次查看(过去 30 天)
显示 更早的评论
Hi , i am trying to perform nearest neighbor and bilinear interpolation on a 512*512 image to convert into 1024*1024 as well as 768*768 . i got some code but not able to proceed further with errors such as "undefined function for input argument double" please help me to convert to 1024*1024 as well as 768*768 without using imresize
here is the following code and attached is the image
inputI= imread('lenatest3.jpg');
[r c] = size(inputI);
scale=2;
for i=1: scale *r
for j=1: scale *c
% map from output image location to input image location by nearest neighbor
ii = round( (i-1)*(r-1)/( scale *r-1)+1 );
jj = round( (j-1)*(c-1)/( scale *c-1)+1 );
% assign value
nni(i,j) = inputI(ii,jj);
end
end
% bilinear
scale=2;
blin=uint8(zeros(r*scale,c*scale));
for i=1:1:size(blin,1)-scale
for j=1:1:size(blin,2)-scale
A=im(ceil(i/scale),ceil(j/scale));
B=im(ceil(i/scale)+1,ceil(j/scale));
C=im(ceil(i/scale),ceil(j/scale)+1);
D=im(ceil(i/scale)+1,ceil(j/scale)+1);
ii=mod(i-1,scale)/scale;
jj=mod(j-1,scale)/scale;
blin(i,j)=A+ii*(B-A)+jj*(C-A+ii*(D+A-C-B));
end
end
0 个评论
回答(1 个)
Image Analyst
2014-11-10
Don't do any of that. Simply call imresize().
2 个评论
Image Analyst
2014-11-10
编辑:Image Analyst
2014-11-10
Why? Is this homework? You didn't tag it as homework. How about interp2()? Or is that not allowed either? Maybe I'll have time to look at it later....
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!