1 ## Copyright (C) 2002 Jeff Orchard
3 ## This program is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU General Public License
5 ## as published by the Free Software Foundation; either version 2
6 ## of the License, or (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{Y}} = imtranslate (@var{M}, @var{x}, @var{y} [, @var{bbox}])
18 ## Translate a 2D image by (x,y) using Fourier interpolation.
20 ## @var{M} is a matrix, and is translated to the right by @var{X} pixels
21 ## and translated up by @var{Y} pixels.
23 ## @var{bbox} can be either 'crop' or 'wrap' (default).
27 ## Author: Jeff Orchard <jjo@cs.sfu.ca>
28 ## bug fix: Eugeniy Mikhailov in 2009 (removing fftshift and ifftshift they do no good)
30 function Y = imtranslate(X, a, b, bbox_in)
37 if ( strcmp(bbox, "crop")==1 )
53 X = impad(X, xpad, ypad, 'zeros');
57 [dimy, dimx] = size(X);
59 px = exp(-2*pi*i*a*(0:dimx-1)/dimx);
60 py = exp(-2*pi*i*b*(0:dimy-1)/dimy)'; % actually to correspond to index notation 'b' should be
62 % but I do not want to brake previous version compatibility
63 % note: it also must be done in the cropping iand padding code
66 Y = real(ifft2(y)); % fft return complex number
67 % for integer shifts imaginary part is 0
68 % so real takes care of transfer from complex number to real
70 if ( strcmp(bbox, "crop")==1 )
71 Y = Y( ypad(1)+1:dimy-ypad(2) , xpad(1)+1:dimx-xpad(2));