Thursday, March 12, 2009

Bi-linear Zooming

% Bi linear Zooming
clear all; close all; clc;
newsize(1) = input('enter size greater than image row size: ');
newsize(2) = input('enter size greater than image column size: ');
data = imread('cameraman.tif');
oldsize = size(data);
oldtype = class(data);
data = double(data);
factor = (oldsize(1:2)-1)./(newsize-1);
u = 0:newsize(1)-1;
v = 0:newsize(2)-1;
[U, V] = ndgrid(u, v);
% transform new grid vectors to old grid size
u1 = u.*factor(1) + 1;
v1 = v.*factor(2) + 1;

% Compute the location of each new point relative to one nearest
% neighbor of the original image
U = U.*factor(1);
U = U - fix(U);
V = V.*factor(2);
V = V - fix(V);
g = (V-1).*((U-1).*data(floor(u1), floor(v1)) - ...
U.*data(ceil(u1), floor(v1))) - ...
V.*((U-1).*data(floor(u1), ceil(v1)) - ...
U.*data(ceil(u1), ceil(v1)));
g = uint8(g);
figure,imshow(g);

No comments: