Skip to content

Latest commit

 

History

70 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ndfilters

tests codecov Black Ruff Documentation Status PyPI version

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 axis argument, 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 where mask excludes selected elements of the input array from the calculation.
  • Physical units. Inputs can be either numpy.ndarray or astropy.units.Quantity instances.
  • 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.

Installation

ndfilters is published on PyPI and can be installed using pip.

pip install ndfilters

Quickstart

Every 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)

Gallery

Mean filter

The mean filter calculates a multidimensional rolling mean for the given kernel shape.

mean filter

Trimmed mean filter

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.

trimmed mean filter

Median filter

The median filter calculates a multidimensional rolling median for the given kernel shape.

median filter

Variance filter

The variance filter calculates the rolling variance for the given kernel shape.

variance filter

Generic filter

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.

generic filter

Convolution

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.

convolve

Releases

Used by

Contributors

Languages