intersect#
- medicalimageanalysis.utils.roi.operations.intersect(rois, grid, margins=None, output='mesh', reduction=0.5, **kw)[source]
Intersection of several ROIs: rois[0] & rois[1] & …
- Parameters:
rois (list) – ROIs (contours, meshes or masks; types can be mixed).
grid (Grid) – Common CT grid.
margins (list | None) – One margin per ROI (mm, scalar or (x, y, z)), applied before intersecting. None for no margins.
output (str) – ‘mesh’, ‘contours’ or ‘mask’.
reduction (float) – Decimation fraction when output=’mesh’.
**kw – Extra options passed to the contour / mesh conversions.
- Returns:
The intersection in the requested format.
- Return type:
vtk.vtkPolyData | list[np.ndarray] | np.ndarray
- Raises:
ValueError – If the number of margins does not match the number of ROIs.
Examples
>>> import numpy as np >>> from medicalimageanalysis.utils.roi.operations import Grid, intersect >>> grid = Grid((16, 64, 64), np.zeros(3), np.ones(3), np.eye(3)) >>> a = np.zeros((16, 64, 64), dtype=np.uint8) >>> a[4:12, 16:40, 16:40] = 255 >>> b = np.zeros((16, 64, 64), dtype=np.uint8) >>> b[4:12, 28:52, 28:52] = 255
Overlap of two ROIs:
>>> overlap = intersect([a, b], grid, output="mask") >>> bool(overlap[8, 34, 34] >= 128), bool(overlap[8, 20, 20] >= 128) (True, False)
Part of the PTV within 2 mm inside the liver:
>>> ptv_in_liver = intersect([ptv, liver], grid, margins=[0, -2])