0

here, i want to zoom in my image(gray) using bi-linear interpolation method, but i not able generate final out put image properly,here is the matlab code :

I = imread('house.png');              %image i want to zoom in
fact = 1.5;
[rows,cols] = size(I);
Jrows = fact * rows;
Jcols = fact * cols;
J = zeros(floor(fact * size(I)));

I = [I(1,:);I];
I = [I;I(end,:)];                       %replicating boundaries.
I = [I(:,1) ,I];
I = [I,I(:,end)];
I = double(I);

for i = 2: Jrows-2
for j = 2: Jcols-2
x1 = floor(i/fact);  
x2 =  ceil(i/fact); 
y1 = floor(j/fact);                %finding neighbours
y2 =  ceil(j/fact);
if x1==0 
x1=1;
end
if y1==0
y1=1;
end
J(i-1,j-1) = (I(x1,y1)*(x2-i)*(y2-j) + I(x2,y1)*(i-x1)*(y2-j)+ I(x1,y2)*(x2-i)*(j-y1) + I(x2,y2)*(i-x1)*(j-y1));
end
end
figure,imshow(uint8(J)),title('zoom in image');    #final image

in this code i m getting zoom image but i lost some pixel values and i am not getting proper image.

Gaurang Rokad
  • 37
  • 1
  • 2
  • 6
  • The link I referenced you to is not an **exact** duplicate, but you need to resize the image first using bilinear interpolation. Then when you're done, simply crop whichever part of the image you want and that will constitute as your zoomed image. Choose a centre pixel in the zoomed image that you want, and extract out pixels that are the dimensions of the original image. – rayryeng Feb 03 '15 at 20:55

1 Answers1

0

There is an excellent builtin matlab function for this: imresize. In this you can specify several details like interpolation method and filter kernel. Just hit F1 while imresize is selected in the matlab gui.

fact = 1.5;

% read image and make greyscale if necessary
I = double(imread('house.png'));
if size(I, 3) == 3
   I = I(:, :, 1)*0.299 + I(:, :, 2)*0.587 + I(:, :, 1)*0.114;
end

% one-liner??
J = uint8(imresize(I, fact, 'bilinear'));

This way you can save some time from writing this manually.