[Numpy-discussion] strange behavior convolving via fft

Chris Colbert sccolbert@gmail....
Mon May 11 13:45:27 CDT 2009


Ok, that makes sense.

Thanks Chuck.



On Mon, May 11, 2009 at 2:41 PM, Charles R Harris <charlesr.harris@gmail.com
> wrote:

>
>
> On Mon, May 11, 2009 at 9:40 AM, Chris Colbert <sccolbert@gmail.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.
>
> Chuck
>
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090511/0f8e71ac/attachment.html 


More information about the Numpy-discussion mailing list