[SciPy-dev] fast gaussian filtering

Sturla Molden sturla@molden...
Fri Dec 19 11:45:59 CST 2008

On 12/19/2008 6:31 PM, Zachary Pincus wrote:

> A brief look at the implementation in scipy/ndimage/filters.py shows  
> that scipy.ndimage.gaussian_filter, after doing some set-up, defers to  
> gaussian_filter1d to do the filtering on each dimension (as Gaussian  
> filtering is separable). Then gaussian_filter1d uses for-loops to do  
> some further set-up, like calculating the filter kernel, and then  
> defers to correlate1d for the actual filtering.  This function does
> some error-checking, and then calls _nd_image.correlate1d. 

Ok, sorry, I did not read the code thoroughly then. :)

> Aside from the several thin layers of error-checking and set-up, the  
> code does the filtering in C in about the fastest way possible that  
> doesn't use recursion or FFT. (And even then, I don't know under what  
> circumstances the direct-convolution method might still win --  
> probably with small kernels.)

Yes, for kernels smaller than 10 or so it will be faster. But a Gaussian 
is actually not of finite size. So a finite sized Gaussian is actually a 
misnomer; it should be a truncated Gaussian. The recursion does not 
truncate the Gaussian kernel (but at some point the impulse response 
will be so small that it falls into the range of rounding error).

Sturla Molden

More information about the Scipy-dev mailing list