image_threshold#

UniformGrid.image_threshold(threshold, in_value=1, out_value=0, scalars=None, preference='point', progress_bar=False)#

Apply a threshold to scalar values in a uniform grid.

If a single value is given for threshold, scalar values above or equal to the threshold are 'in' and scalar values below the threshold are 'out'. If two values are given for threshold (sequence) then values equal to or between the two values are 'in' and values outside the range are 'out'.

If None is given for in_value, scalars that are 'in' will not be replaced. If None is given for out_value, scalars that are 'out' will not be replaced.

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.

Parameters
thresholdfloat or sequence

Single value or (min, max) to be used for the data threshold. If a sequence, then length must be 2. Threshold(s) for deciding which cells/points are 'in' or 'out' based on scalar data.

in_valuefloat or int or None, optional

Scalars that match the threshold criteria for 'in' will be replaced with this. Default is 1.

out_valuefloat or int or None, optional

Scalars that match the threshold criteria for 'out' will be replaced with this. Default is 0.

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. Default False.

Returns
pyvista.UniformGrid

Dataset with the specified scalars thresholded.

Examples

Demonstrate image threshold on an example dataset. First, plot the example dataset with the active scalars.

>>> from pyvista import examples
>>> uni = examples.load_uniform()
>>> uni.plot()
../../../_images/pyvista-UniformGrid-image_threshold-1_00_00.png

Now, plot the image threshold with threshold=100. Note how values above the threshold are 1 and below are 0.

>>> ithresh = uni.image_threshold(100)
>>> ithresh.plot()
../../../_images/pyvista-UniformGrid-image_threshold-1_01_00.png