pyvista.ImageDataFilters.close#
- ImageDataFilters.close(
- kernel_size: int | VectorLike[int] = (3, 3, 3),
- scalars: str | None = None,
- *,
- binary: bool | VectorLike[float] | None = None,
- progress_bar: bool = False,
Perform morphological closing on continuous or binary data.
Closing is a
dilationfollowed by anerosion. It is used to fill small holes/gaps while preserving the shape and size of larger objects.Added in version 0.47.
- Parameters:
- kernel_size
int|VectorLike[int], default: (3, 3, 3) Determines the size of the kernel along the xyz-axes. Only non-singleton dimensions are closed, e.g. a kernel size of
(3, 3, 1)and(3, 3, 3)produce the same result for 2D images.- scalars
str,optional Name of scalars to process. Defaults to currently active scalars.
- binarybool |
VectorLike[float],optional Control if binary closing or continuous closing is used. Refer to
dilate()and/orerode()for details about using this keyword.- progress_barbool, default:
False Display a progress bar to indicate progress.
- kernel_size
- Returns:
pyvista.ImageDataDataset that has been closed.
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 withcell_data_to_point_data().Examples
Load a binary image:
download_yinyang().>>> from pyvista import examples >>> im = examples.download_yinyang()
Use
closewith a relatively small kernel to fill the top black edge of the yinyang.>>> closed = im.close(kernel_size=5) >>> kwargs = dict( ... cmap='grey', ... lighting=False, ... cpos='xy', ... zoom='tight', ... show_axes=False, ... show_scalar_bar=False, ... ) >>> closed.plot(**kwargs)
Use a much larger kernel to also fill the small black circle.
>>> closed = im.close(kernel_size=25) >>> closed.plot(**kwargs)
Since closing is the inverse of opening, we can alternatively use
open()to fill the white foreground values instead of the black background.>>> opened = im.open(kernel_size=25) >>> opened.plot(**kwargs)