[SciPy-user] shift FFT2D...
Francesc Altet
faltet at carabos.com
Wed May 9 11:06:15 EDT 2007
El dc 09 de 05 del 2007 a les 16:40 +0200, en/na fred va escriure:
> Hi all,
>
> I use an FFT 2D on a matrix to compute a convolution like this:
>
> a = fft2(input_data)
> b = fft2(output_data)
> c = real(ifft2(a*b))
>
> The problem is that c should look like this:
>
> c1 | c2
> -----------
> c3 | c4
>
> but it looks like this:
>
> c4 | c3
> -----------
> c2 | c1
>
> How can I get efficiently the right result ? (something like shift ?)
Something like:
N4 = N/4
c1 = c[:N4]; c2 = c[N4:2*N4]; c3 = c[2*N4:3*N4]; c4 = c[3*N4:]
tmp = c1.copy(); c1[:] = c4; c4[:] = tmp
tmp = c2.copy(); c2[:] = c3; c3[:] = tmp
should do the trick.
As c1, c2, c3 and 4 are views and not copies, the above snippet should
be fairly optimal in terms of both speed and memory usage.
HTH,
--
Francesc Altet | Be careful about using the following code --
Carabos Coop. V. | I've only proven that it works,
www.carabos.com | I haven't tested it. -- Donald Knuth
More information about the SciPy-User
mailing list