Sunteți pe pagina 1din 4

Image Zooming Using Bilinear Interpolation in Matlab

Bilinear Interpolation determines the intensity value from the weighted average of the four closest pixels to the specified input coordinates, and assigns that value to the output coordinates. download m-code function bilinear(im,scale) % function bilinear(im,scale) % % This function zoom the input image with to a given scaling factor using % bilinear interpolation % % Inputs % im: name of the image file % scale: zoom factor % %Author:Nuwan Ganganath

im=imread(im); imshow(im); title('Original Image'); if scale>0 [r,c,h]=size(im); blim=uint8(zeros(floor(r*scale),floor(c*scale),h)); for i=1:1:size(blim,1)-scale for j=1:1:size(blim,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; blim(i,j,:)=A+ii*(B-A)+jj*(C-A+ii*(D+A-C-B)); end end figure; imshow(blim); title('Bilinear'); end

Image Zooming Using Bicubic Interpolation in Matlab


Bicubic Interpolation determines the intensity value from the weighted average of the 16 closest pixels to the specified input coordinates, and assigns that value to the output coordinates. download m-code function bicubic(im,scale) % function bicubic(im,scale) % % This function zoom the input image with to a given scaling factor using % bicubic interpolation % % Inputs % im name of the image file % scale zoom factor % %Author:Nuwan Ganganath close all; im=imread(im); imshow(im); title('Original Image'); if scale>0 [r,c,h]=size(im); tempim=uint8(zeros(r+4,c+4,h)); tempim(3:r+2,3:c+2,:)=im(:,:,:); newim=uint8(zeros(floor(r*scale),floor(c*scale),h)); for i=1:1:size(newim,1) for j=1:1:size(newim,2) for x_i=floor((i-1)/scale)+1:1:floor((i-1)/scale)+5 for y_j=floor((j-1)/scale)+1:1:floor((j-1)/scale)+5 x_d=cubicCalcDistance((i-1)/scale+3,x_i); y_d=cubicCalcDistance((j-1)/scale+3,y_j); newim(i,j,:)=newim(i,j,:)+tempim(x_i,y_j,:)*x_d*y_d; end end

end end figure; imshow(newim); title('Bicubic'); end function s = cubicCalcDistance(p,g) d=abs(p-g); if d<1 s=3/2*d^3-5/2*d^2+1; elseif d<2 s=-1/2*d^3+5/2*d^2-4*d+2; else s=0; end return

"Nothing is impossible, but miracles take time." Image Zooming Using Nearest-Neighbour Interpolation in Matlab
Nearest-Neighbour Interpolation determines the intensity value from the closest pixel to the specified input coordinates, and assigns that value to the output coordinates. download m-code function nearestNeighbor(im,scale) function nearestNeighbor(im,scale) % function nearestNeighbor(im,scale) % % This function zoom the input image with to a given scaling factor using % nearest-neighbor interpolation %

% Inputs % im name of the image file % scale zoom factor % %Author: Nuwan Ganganath im=imread(im); imshow(im); title('Original Image'); if scale>0 [r,c,h]=size(im); nnim=uint8(zeros(floor(r*scale),floor(c*scale),h)); for i=1:1:size(nnim,1) for j=1:1:size(nnim,2) nnim(i,j,:)=im(ceil(i/scale),ceil(j/scale),:); end end

figure; imshow(nnim); title('Nearest-neighbour'); end

S-ar putea să vă placă și