trimmed_mean_filter#
- named_arrays.ndfilters.trimmed_mean_filter(array, size, where=True, mode='mirror', proportion=0.25)#
A thin wrapper around
ndfilters.trimmed_mean_filter()for named arrays.- Parameters:
array (ArrayT) – The input array to be filtered.
size (dict[str, int]) – The shape of the kernel over which the mean will be calculated.
where (WhereT) – A boolean mask used to select which elements of the input array are to be filtered.
mode (Literal['mirror', 'nearest', 'wrap', 'truncate']) – The method used to extend the input array beyond its boundaries. See
scipy.ndimage.generic_filter()for the definitions. Currently, only “mirror”, “nearest”, “wrap”, and “truncate” modes are supported.proportion (float) – The proportion to cut from the top and bottom of the distribution.
- Return type:
ArrayT | WhereT
Examples
Filter a sample image.
import numpy as np import matplotlib.pyplot as plt import named_arrays as na x = na.linspace(-5, 5, axis="x", num=201) y = na.linspace(-5, 5, axis="y", num=201) img = np.cos(np.square(x)) * np.cos(np.square(y)) img_filtered = na.ndfilters.trimmed_mean_filter( array=img, size=dict(x=21, y=21), ) fig, axs = plt.subplots( ncols=2, sharex=True, sharey=True, constrained_layout=True, ) axs[0].set_title("original image"); na.plt.imshow( X=img, axis_x="x", axis_y="y", ax=axs[0], cmap="gray", ); axs[1].set_title("filtered image"); na.plt.imshow( X=img_filtered, axis_x="x", axis_y="y", ax=axs[1], cmap="gray", );