Skip to main content

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.

Differences from scipy.ndimage

Where a filter in this library has a scipy.ndimage counterpart, the two agree except in the following cases.

  • Boundary modes. Only "mirror", "nearest", and "wrap" are supported, plus "truncate", which has no scipy.ndimage equivalent and simply drops the parts of the kernel that fall outside the array. SciPy's "reflect", "constant", and "grid-*" modes raise a ValueError here.
  • Integer input. Integer arrays are promoted to floating point, so the result is a float and is not truncated. scipy.ndimage returns the dtype of the input, and for the separable filters it truncates its intermediates as well. The promotion is what lets a where mask that excludes an entire kernel footprint return NaN.
  • Even-sized median footprints. ndfilters.median_filter averages the two middle elements, like numpy.median, while scipy.ndimage.median_filter selects the element of rank size // 2, the larger of the two. SciPy's convention keeps the result in the dtype of the input and never introduces a value that was not already in the footprint, but it is a biased estimator: on unit-variance noise a size=2 filter shifts the signal by roughly 0.57. The two conventions agree exactly for odd-sized footprints.

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)

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

Citation

If you use ndfilters in your research, please cite it. The citation metadata is kept in CITATION.cff, which the "Cite this repository" button on GitHub can export as BibTeX or APA. Please include the version of ndfilters that you used, which is given by importlib.metadata.version("ndfilters").

@software{ndfilters,
  author = {Smart, Roy T.},
  title = {ndfilters},
  version = {X.Y.Z},
  url = {https://github.com/sun-data/ndfilters},
}

Metadata

Release files for ndfilters 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ndfilters 1.1.1
File Size Uploaded
ndfilters-1.1.1.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ndfilters 1.1.1
File Interpreter ABI Platform
ndfilters-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 44.3 kB

Release files / ndfilters-1.1.1.tar.gz

Download URL ndfilters-1.1.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
de1f8939e6cc2acf4ab29e147f90992789b2203773cbf837ebf619d5b6a2e3ea
BLAKE2b-256 checksum
How to use checksums
2342855fcd2a552ad0ad637e9c2a3cb85fb0045052feb0ea0e8b81f2d339a50b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / ndfilters-1.1.1-py3-none-any.whl

Download URL ndfilters-1.1.1-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb5335dfbdffcb4adcaabb6862bfc8757c0baf66d2a62ab3cbb16bafc4aabfcb
BLAKE2b-256 checksum
How to use checksums
af585c38b21df96c99bebb44dba6faaf2db65e7e35692767169c891d44abf210
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page