ImageDataFilters.image_dilate_erode

ImageDataFilters.image_dilate_erode#

ImageDataFilters.image_dilate_erode(
dilate_value: float = 1.0,
erode_value: float = 0.0,
*,
kernel_size: VectorLikeInt = (3, 3, 3),
scalars: str | None = None,
progress_bar: bool = False,
) → ImageData[source]#

Dilates one value and erodes another.

Deprecated since version 0.47.0: image_dilate_erode() is deprecated. Use dilate(), erode(), open(), or close() instead.

image_dilate_erode will dilate one value and erode another. It uses an elliptical footprint, and only erodes/dilates on the boundary of the two values. The filter is restricted to the X, Y, and Z axes for now. It can degenerate to a 2 or 1-dimensional filter by setting the kernel size to 1 for a specific axis.

Parameters:
dilate_valuefloat, default: 1.0

Dilate value in the dataset.

erode_valuefloat, default: 0.0

Erode value in the dataset.

kernel_sizeVectorLikeInt, default: (3, 3, 3)

Determines the size of the kernel along the three axes.

scalarsstr, optional

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

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.ImageData

Dataset that has been dilated/eroded on the boundary of the specified scalars.

Notes#

This filter only supports point data. For inputs with cell data, consider re-meshing the cell data as point data with cells_to_points() or resampling the cell data to point data with cell_data_to_point_data().

Examples#

Download Python source code | Download Jupyter notebook

Demonstrate image dilate/erode 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_dilate_erode-d800e531e8ede368_00_00.png

Now, plot the image threshold with threshold=[400, 600]. Note how values within the threshold are 1 and outside are 0.

>>> ithresh = uni.image_threshold([400, 600])
>>> ithresh.plot()
../../../_images/pyvista-ImageDataFilters-image_dilate_erode-d800e531e8ede368_01_00.png

Note how there is a hole in the thresholded image. Apply a closing filter with a large kernel to fill that hole in.

>>> iclosed = ithresh.close(kernel_size=[5, 5, 5])
>>> iclosed.plot()
../../../_images/pyvista-ImageDataFilters-image_dilate_erode-d800e531e8ede368_02_00.png