ImageDataFilters.image_threshold

ImageDataFilters.image_threshold#

ImageDataFilters.image_threshold(
threshold: float | VectorLikeFloat,
*,
in_value: float | None = 1.0,
out_value: float | None = 0.0,
scalars: str | None = None,
preference: PointLiteral | CellLiteral = 'point',
progress_bar: bool = False,
) → ImageData[source]#

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.

Thresholded cell scalars are returned as cell data, and all other arrays are passed through unchanged.

Parameters:
thresholdfloat | VectorLikeFloat

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

in_valuefloat | None, default: 1.0

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

out_valuefloat | None, default: 0.0

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

scalarsstr, optional

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

preferencestr, default: “point”

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

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.ImageData

Dataset with the specified scalars thresholded.

Examples#

Download Python source code | Download Jupyter notebook

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-ImageDataFilters-image_threshold-adf0d3a73ed2e667_00_00.png

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

../../../_images/pyvista-ImageDataFilters-image_threshold-adf0d3a73ed2e667_01_00.png

See Also#

select_values

Threshold-like method for keeping some values and replacing others.

threshold()

General threshold method that returns a UnstructuredGrid.