manual bilinear and nearest neighbor interpolation

10 views (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 10 Nov 2014
Don't do any of that. Simply call imresize().
  2 Comments
tilak tenneti
tilak tenneti on 10 Nov 2014
thank you sir but as a task of my work i am required to do the manual task of achieving bilinear and nearest neighbor without using imresize().
any help would be appreciated
thanks
Image Analyst
Image Analyst on 10 Nov 2014
Edited: Image Analyst on 10 Nov 2014
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....

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!