erode#
- medicalimageanalysis.utils.roi.operations.erode(roi, grid, mm, output='mesh', reduction=0.5, **kw)[source]
Shrink one ROI by a margin in mm (given as a positive number).
- Parameters:
roi (list[np.ndarray] | dict | vtk.vtkPolyData | np.ndarray) – Contours, closed mesh, or uint8 mask on grid.
grid (Grid) – Common CT grid.
mm (float | tuple[float, float, float]) – Amount to shrink by in mm, scalar or (x, y, z). Must be >= 0.
output (str) – ‘mesh’, ‘contours’ or ‘mask’.
reduction (float) – Decimation fraction when output=’mesh’.
**kw – Extra options passed to the contour / mesh conversions.
- Returns:
The shrunk ROI in the requested format.
- Return type:
vtk.vtkPolyData | list[np.ndarray] | np.ndarray
- Raises:
ValueError – If any margin is negative.
Examples
>>> import numpy as np >>> from medicalimageanalysis.utils.roi.operations import Grid, erode >>> grid = Grid((16, 64, 64), np.zeros(3), np.ones(3), np.eye(3)) >>> organ = np.zeros((16, 64, 64), dtype=np.uint8) >>> organ[2:14, 16:48, 16:48] = 255
3 mm everywhere:
>>> inner = erode(organ, grid, 3, output="mask") >>> bool(inner[8, 18, 32] >= 128) # 2 mm from the old edge False
Shrink a mesh in-plane only:
>>> inner_mesh = erode(organ_mesh, grid, (3, 3, 0))