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

Aronne Merrelli aronne.merrelli@gmail....
Fri Oct 19 13:58:17 CDT 2012


On Fri, Oct 19, 2012 at 1:19 PM, Moore, Eric (NIH/NIDDK) [F]
<eric.moore2@nih.gov> wrote:
>
> 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.
>
>

Nice - thanks for pointing this out, Eric, I didn't realize there was
already an implementation.

Patrick, try comparing these two with your data:

data_conv = scipy.ndimage.convolve(data, kernel, mode='constant')

data_fftconv = scipy.signal.fftconvolve(data, kernel, mode='same')


They look to be equal within floating point error on my machine, with
a flat kernel and gaussian noise for data. The fftconvolve becomes
enormously much faster than the simple convolve as the kernel becomes
a sizeable fraction of the size of the data array. You'll need to pick
different modes perhaps depending on what you want for your specific
case.

(BTW, Your IP notebook is correct, the shifting is just one of the
things you need to deal with when transforming to frequency space and
back, but since there is already an implementation in scipy.signal you
don't need to worry about it)


Aronne


More information about the SciPy-User mailing list