Image Zooming
Image Zooming
Image Zooming
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
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