Hi Søren,
Well I found what was causing the misbehavior: there were redundant
fftshift and ifftshiftm
they do not do any good so I removed it. Everything works as it should now.
It seems to me that this discrete Fourier procedure is correct only
for integer shifts, thus may be a warning should be issued to a user
for fractional shifts, or even an error message. In the last case we
can replaced the translate with several consequent padding and
cropping.
See my bug fix in the attachment.
On Sat, Apr 18, 2009 at 5:23 AM, Søren Hauberg <[email protected]> wrote:
> Hi
>
> Thanks for reporting this.
>
> fre, 17 04 2009 kl. 12:39 -0400, skrev Eugeniy Mikhailov:
>> suppose to shift/translate image but if (x_shift+y_shift) is odd
>> the resulting image get multiplied by -1.
> [snip]
>> === suggested fix: multiply the final result by (-1)^(shift_x+shift_y)
>
> This will only work when (shift_x+shift_y) is an integer. Does anybody
> have a better solution that also works for fractional shifts?
>
>
>> ============== 2nd bug ========================================
>> Severe precision drop for small images:
> [snip]
>> Looks like problem is actually in the fft which used for translation,
>> since imtranslate algorithm
>> seems to be correct one. But I do not see an easy fix for second problem.
>
> I must admit that I don't really follow the algorithm, so I cannot
> really comment here.
>
>> It is a bit unclear to me why use fft is used for translation. Since
>> integer shift could be done in a simpler way, fractional shift is
>> another story.
>
> Yeah, I never really understood why anybody would use the Fourier
> transform in interpolation. It seems like a poor choice to use sine
> curves for interpolation, except in specialised situations. I think the
> 'imtranslate' function should be altered to except string that allows
> you to pick an interpolation method. Just like the rest of the
> interpolation functions in the package. Unfortunately, I don't have the
> time at the moment to work on this, so if anybody want to help out it
> would be much appreciated.
>
> Søren
>
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> Octave-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/octave-dev
>
--
Eugeniy
Index: imtranslate.m
===================================================================
--- imtranslate.m (revision 5722)
+++ imtranslate.m (working copy)
@@ -25,6 +25,7 @@
## @end deftypefn
## Author: Jeff Orchard <[email protected]>
+## 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));
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev