[SciPy-User] fft convolutions
Sturla Molden
sturla at molden.no
Thu Jun 30 04:35:12 EDT 2011
Den 28.06.2011 20:17, skrev Alex Flint:
> I am trying to perform 2d convolutions between a large 2d array A and
> a bunch of small 2d arrays B1...Bn. My approach is roughly:
>
> a = fft(A,size)
> for b in bs:
> ans = ifft(fft(b,size)*A)
> slow = convolve2d(A, b, 'same')
>
> However, as implemented above, ans is offset an inconsistent amount
> from the answer produced by convolve2d, presumably because convolve2d
> is treating b as if the origin is in the center whereas fft treats b
> as if the origin is at the top left (but it doesn't seem to be quite
> as simple as this). What am I missing?
You are not doing 2D convolution with the FFT. You want fft2 (or rfft2).
Sturla
More information about the SciPy-User
mailing list