- UniformGridFilters.median_smooth(kernel_size=(3, 3, 3), scalars=None, preference='point', progress_bar=False)#
Smooth data using a median filter.
The Median filter that replaces each pixel with the median value from a rectangular neighborhood around that pixel. Neighborhoods can be no more than 3 dimensional. Setting one axis of the neighborhood kernelSize to 1 changes the filter into a 2D median.
See vtkImageMedian3D for more details.
Length 3 list or tuple of ints :
(x_size, y_size, z_size)Size of the kernel in each dimension (units of voxels). Default is a 3D median filter. If you want to do a 2D median filter, set the size to 1 in the dimension you don’t want to filter over.
Name of scalars to process. Defaults to currently active scalars.
When scalars is specified, this is the preferred array type to search for in the dataset. Must be either
Display a progress bar to indicate progress.
Uniform grid with smoothed scalars.
Applying this filter to cell data will send the output to a new point array with the same name, overwriting any existing point data array with the same name.
First, create sample data to smooth. Here, we use
pyvista.perlin_noise()to create meaningful data.
>>> import numpy as np >>> import pyvista >>> noise = pyvista.perlin_noise(0.1, (2, 5, 8), (0, 0, 0)) >>> grid = pyvista.sample_function(noise, [0, 1, 0, 1, 0, 1], dim=(20, 20, 20)) >>> grid.plot(show_scalar_bar=False)
Next, smooth the sample data.
>>> smoothed = grid.median_smooth(kernel_size=(10, 10, 10)) >>> smoothed.plot(show_scalar_bar=False)