[Numpy-discussion] strange behavior convolving via fft
Charles R Harris
Mon May 11 13:41:59 CDT 2009
On Mon, May 11, 2009 at 9:40 AM, Chris Colbert <email@example.com> wrote:
> at least I think this is strange behavior.
> When convolving an image with a large kernel, its know that its faster to
> perform the operation as multiplication in the frequency domain. The below
> code example shows that the results of my 2d filtering are shifted from the
> expected value a distance 1/2 the width of the filter in both the x and y
> directions. Can anyone explain why this occurs? I have been able to find the
> answer in any of my image processing books.
> The code sample below is an artificial image of size (100, 100) full of
> zeros, the center of the image is populated by a (10, 10) square of 1's. The
> filter kernel is also a (10,10) square of 1's. The expected result of the
> convolution would therefore be a peak at location (50,50) in the image.
> Instead, I get (54, 54). The same shifting occurs regardless of the image
> and filter (assuming the filter is symetric, so flipping isnt necessary).
Your kernel is offset and the result is expected. The kernel needs to be
centered on the origin, aliasing will then put parts of it in all four
corners of the array *before* you transform it. If you want to keep it
simple you can phase shift the transform instead.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion