median_smooth#

UniformGrid.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.

Parameters
kernel_sizelist(int) or tuple(int), optional

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.

scalarsstr, optional

Name of scalars to process. Defaults to currently active scalars.

preferencestr, optional

When scalars is specified, this is the preferred array type to search for in the dataset. Must be either 'point' or 'cell'.

progress_barbool, optional

Display a progress bar to indicate progress.

Returns
pyvista.UniformGrid

Uniform grid with smoothed scalars.

Warning

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.

Examples

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)
../../../_images/pyvista-UniformGrid-median_smooth-1_00_00.png

Next, smooth the sample data.

>>> smoothed = grid.median_smooth(kernel_size=(10, 10, 10))
>>> smoothed.plot(show_scalar_bar=False)
../../../_images/pyvista-UniformGrid-median_smooth-1_01_00.png