[SciPy-User] Rotated, Anisotropic Gaussian Filtering (Kernel Density Estimation)

Moore, Eric (NIH/NIDDK) [F] eric.moore2@nih....
Fri Oct 19 13:19:48 CDT 2012

From: Patrick Marsh [mailto:patrickmarshwx@gmail.com]
Sent: Friday, October 19, 2012 1:18 PM
To: SciPy Users List
Subject: Re: [SciPy-User] Rotated, Anisotropic Gaussian Filtering (Kernel Density Estimation)

On Fri, Oct 19, 2012 at 9:34 AM, Daπid <davidmenhur@gmail.com<mailto:davidmenhur@gmail.com>> wrote:
If you are going to apply different filters to the same image, it may
be faster to switch to the Fourier transform. In  this case, the
result is the IFT of the FT of your data multiplied by the FT of your

Doing all the FT may be expensive, but it can be useful if you are
reusing the data, and Scipy is linked to very optimized FFT libraries.

Thanks to all who have taken time to respond to my initial email. I'm learning a lot here.

With that said, I'm intrigued with the idea of using FFTs. I knew it was possible but had never actually looked into how to do it. As a simple experiment, I generated a simple kernel using my Cython code and took the FFT of this 2D array. I then attempted to apply it using the IFFT(FFT(kernel) * FFT(hist)) method described about. You can see the result here: http://nbviewer.ipython.org/3919393/. Obviously, I'm doing something wrong here, but I'm not sure what. Why is the result separated into the four corners and not the center of the grid? Any help in figuring this out…or pointers to references...would be appreciated.

Also, I'm assuming that the kernel and the image need to be the same dimensions or the multiplication won't work?

Thanks again to all for helping wrap my head around this.


Have you tried the fftconvolve function in scipy.signal?  I’m not sure why your plot appears to have been shifted,  are you sure you never called fftshift?  Also there are some details about the size used for the ffts.

All of this rotation business seems unnecessary even for your current technique.  You can’t use the rotation angle directly in the calculation of your Gaussian? And then just add add pointwise? This ought to be faster than the doing the full convolution for very sparse, but densely meshed histograms if your kernel is small.  If you’re not sure what I mean, wikipedia’s article on the Gaussian has a nice explanation: http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121019/0e8e87e7/attachment.html 

More information about the SciPy-User mailing list