function y = zoom2(x,ax,ay)
% ZOOM2 applies zoom to an image represented by a single matrix of values.
%
% [Y] = ZOOM2(X,AX,AY) scales the original image (X) by AX and AY. The
% result is stored in Y. To enlarge, 'AX/Y > 1', and to reduce, '0 < AX/Y
% < 1'.
% Copyright (C) Iván López Espejo 2010
% Version: Id: zoom2.m , v 1.0 2010
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You can obtain a copy of the GNU General Public License from
% ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0 or by writing to
% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = double(x);
filas = length(x(:,1));
columnas = length(x(1,:));
y = zeros(round(filas*ax),round(columnas*ay));
for j = 1:1:length(y(:,1))
for k = 1:1:length(y(1,:))
h = round(j/ax);
while h > filas
h = h - 1;
end
while h < 1
h = h + 1;
end
i = round(k/ay);
while i > columnas
i = i - 1;
end
while i < 1
i = i + 1;
end
y(j,k) = x(h,i);
end
end
y = uint8(y);
figure
imshow(uint8(x)), title('Imagen original');
figure
imshow(y), title('Zoom de la imagen');