subtract#
- medicalimageanalysis.utils.roi.operations.subtract(main, others, grid, margins=None, output='mesh', reduction=0.5, **kw)[source]
Subtract ROIs: main minus (others[0] | others[1] | …).
- Parameters:
main (list[np.ndarray] | dict | vtk.vtkPolyData | np.ndarray) – ROI to subtract from.
others (list | ROI) – ROIs to remove. A single ROI is also accepted (a contour list counts as one ROI).
grid (Grid) – Common CT grid.
margins (list | None) – One margin per ROI in the order [main, *others], applied first. 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 remaining ROI 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, subtract >>> 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
a minus b:
>>> rest = subtract(a, b, grid, output="mask") >>> bool(rest[8, 20, 20] >= 128), bool(rest[8, 34, 34] >= 128) (True, False)
Optimization structure: PTV minus (rectum + 3 mm) minus (bladder + 3 mm):
>>> ptv_opt = subtract(ptv, [rectum, bladder], grid, margins=[0, 3, 3])