skimage2.filters.median#

skimage2.filters.median(image, footprint=None, out=None, mode='nearest', cval=0.0, behavior='ndimage')[source]#

Return local median of an image.

Parameters:
imagearray-like

Input image.

footprintndarray, optional

If behavior='rank', footprint is a 2-D array of 1’s and 0’s. If behavior='ndimage', footprint is a N-D array of 1’s and 0’s with the same number of dimensions as image. If None, footprint will be a N-D array with 3 elements for each dimension (e.g., vector, square, cube, etc.).

outndarray, optional

If None, a new array is allocated. For behavior='ndimage', dtype matches input. For behavior='rank', dtype follows skimage.filters.rank.median().

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to ‘constant’. Default is ‘nearest’.

Added in version 0.15: mode is used when behavior='ndimage'.

cvalscalar, optional

Value to fill past edges of input image if mode is ‘constant’. Default is 0.0.

Added in version 0.15: cval was added in 0.15 and is used when behavior='ndimage'.

behavior{‘ndimage’, ‘rank’}, optional

Whether to use the old (i.e., scikit-image < 0.15) or the new behavior. The old behavior will call skimage.filters.rank.median(). The new behavior will call scipy.ndimage.median_filter(). Default is ‘ndimage’.

Added in version 0.15: behavior is introduced in v0.15.

Changed in version 0.16: Default behavior has been changed from ‘rank’ to ‘ndimage’.

Returns:
outndarray

Output image. For behavior='ndimage', dtype matches input. For behavior='rank', dtype follows skimage.filters.rank.median().

See also

skimage.filters.rank.median

Rank-based implementation of the median filtering offering more flexibility with additional parameters but dedicated for unsigned integer images.

Examples

>>> import _skimage2 as ski2
>>> img = ski2.data.camera()
>>> med = ski2.filters.median(img, ski2.morphology.disk(5))