ndfilters is a library of n-dimensional image filters similar to those in
scipy.ndimage,
but accelerated and parallelized using
Numba.
Compared to their scipy.ndimage equivalents, the filters in this library
offer some additional capabilities:
- Axis selection. Every filter accepts an
axisargument, so the kernel can be applied to any subset of the array's axes while the remaining axes act as batch dimensions. - Masking. A boolean
wheremask excludes selected elements of the input array from the calculation. - Physical units. Inputs can be either
numpy.ndarrayorastropy.units.Quantityinstances. - Varying kernels. The convolution kernel is allowed to change along axes orthogonal to the convolution axes.
The full documentation is hosted on Read the Docs.
ndfilters is published on PyPI and can be installed using pip.
pip install ndfiltersEvery filter takes an array and the shape of the kernel, and returns the filtered array.
import scipy.datasets
import ndfilters
img = scipy.datasets.ascent()
img_filtered = ndfilters.median_filter(img, size=21)The mean filter calculates a multidimensional rolling mean for the given kernel shape.
The trimmed mean filter is like the mean filter except it ignores a given portion of the dataset before calculating the mean at each pixel.
The median filter calculates a multidimensional rolling median for the given kernel shape.
The variance filter calculates the rolling variance for the given kernel shape.
The generic filter applies an arbitrary compiled function to each kernel footprint. It is the engine behind the other rolling filters in this library, and it can be used directly to build custom filters.
ndfilters.convolve()
convolves an array with a given kernel.
Unlike scipy.ndimage.convolve() or astropy.convolution.convolve(),
the kernel is allowed to vary along axes orthogonal to the convolution axes.





