changeset 368:1fa9ce890166

Allow for odd shifts (from Eugeniy Mikhailov)
author hauberg
date Wed, 22 Apr 2009 19:10:33 +0000
parents adf5b6998ace
children 7cfd8a5a581a
files inst/imtranslate.m
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/inst/imtranslate.m
+++ b/inst/imtranslate.m
@@ -25,6 +25,7 @@
 ## @end deftypefn
 
 ## Author: Jeff Orchard <jjo@cs.sfu.ca>
+## bug fix: Eugeniy Mikhailov in 2009 (removing fftshift and ifftshift they do no good)
 
 function Y = imtranslate(X, a, b, bbox_in)
 
@@ -54,13 +55,17 @@
 
 
 	[dimy, dimx] = size(X);
-	x = ifftshift(fft2(fftshift(X)));
+	x = fft2(X);
 	px = exp(-2*pi*i*a*(0:dimx-1)/dimx);
-	py = exp(-2*pi*i*b*(0:dimy-1)/dimy)';
+	py = exp(-2*pi*i*b*(0:dimy-1)/dimy)'; 	% actually to correspond to index notation 'b' should be
+						% replaced with '-b'
+						% but I do not want to brake previous version compatibility
+						% note: it also must be done in the cropping iand padding code
 	P = py * px;
 	y = x .* P;
-	Y = real( ifftshift(ifft2(fftshift(y))) );
-	#Y = ifftshift(ifft2(fftshift(y)));
+	Y = real(ifft2(y)); 	% fft return complex number
+				% for integer shifts imaginary part  is 0 
+				% so real takes care of transfer from complex number to real
 
 	if ( strcmp(bbox, "crop")==1 )
 		Y = Y(  ypad(1)+1:dimy-ypad(2) , xpad(1)+1:dimx-xpad(2));