dilate#
- medicalimageanalysis.utils.roi.operations.dilate(roi, grid, mm, output='mesh', reduction=0.5, **kw)[source]
Grow one ROI by a margin in mm.
- 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]) – Margin 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 grown 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, dilate >>> grid = Grid((16, 64, 64), np.zeros(3), np.ones(3), np.eye(3)) >>> ctv = np.zeros((16, 64, 64), dtype=np.uint8) >>> ctv[4:12, 24:40, 24:40] = 255
5 mm everywhere, returned as a mesh:
>>> ptv = dilate(ctv, grid, 5)
Anisotropic margin (3 mm in x / y, 6 mm in z), kept as a mask:
>>> ptv_mask = dilate(ctv, grid, (3, 3, 6), output="mask") >>> int((ptv_mask >= 128).sum()) > int((ctv >= 128).sum()) True
Dilate RTSTRUCT contours and get contours back:
>>> ptv_rings = dilate(ctv_rings, grid, 5, output="contours")