Dose#
The dose structures page groups the dose container and its display helper together.
- class medicalimageanalysis.structure.dose.Dose(dose)[source]#
Bases:
ImageOne RTDOSE volume: an
Imagewith dose scaling, a 0 Gy background and DVH statistics.- Parameters:
dose (object) – Reader output providing image_set, array, dose_name, modality, filepaths, sops, plane, spacing, orientation, origin and image_matrix.
- DEFAULT_METRICS#
Class attribute: metrics
compute_roi_metrics()reports when none are named: Volume, Dmin, Dmax, Dmean, Dmedian, Dstd, D1, D2, D5 … D95, D98, D99, and V0Gy … V150Gy in % and cc.
Examples
>>> import medicalimageanalysis as mia >>> dose = mia.Data.dose[mia.Data.dose_list()[0]] >>> dose.origin, dose.spacing, dose.array.shape >>> dose.get_window() [0.0, 72.4]
- background = 0.0#
- DEFAULT_METRICS = ['Volume', 'Dmin', 'Dmax', 'Dmean', 'Dmedian', 'Dstd', 'D1', 'D2', 'D5', 'D10', 'D15', 'D20', 'D25', 'D30', 'D35', 'D40', 'D45', 'D50', 'D55', 'D60', 'D65', 'D70', 'D75', 'D80', 'D85', 'D90', 'D95', 'D98', 'D99', 'V0Gy', 'V5Gy', 'V10Gy', 'V15Gy', 'V20Gy', 'V25Gy', 'V30Gy', 'V35Gy', 'V40Gy', 'V45Gy', 'V50Gy', 'V55Gy', 'V60Gy', 'V65Gy', 'V70Gy', 'V75Gy', 'V80Gy', 'V85Gy', 'V90Gy', 'V95Gy', 'V100Gy', 'V105Gy', 'V110Gy', 'V115Gy', 'V120Gy', 'V125Gy', 'V130Gy', 'V135Gy', 'V140Gy', 'V145Gy', 'V150Gy', 'V0Gy_cc', 'V5Gy_cc', 'V10Gy_cc', 'V15Gy_cc', 'V20Gy_cc', 'V25Gy_cc', 'V30Gy_cc', 'V35Gy_cc', 'V40Gy_cc', 'V45Gy_cc', 'V50Gy_cc', 'V55Gy_cc', 'V60Gy_cc', 'V65Gy_cc', 'V70Gy_cc', 'V75Gy_cc', 'V80Gy_cc', 'V85Gy_cc', 'V90Gy_cc', 'V95Gy_cc', 'V100Gy_cc', 'V105Gy_cc', 'V110Gy_cc', 'V115Gy_cc', 'V120Gy_cc', 'V125Gy_cc', 'V130Gy_cc', 'V135Gy_cc', 'V140Gy_cc', 'V145Gy_cc', 'V150Gy_cc']#
- add_model(roi_names, kind='tet', name=None, cavities=None, cluster_points=None, edge_length_fac=0.05, edge_length_abs=None, region_edge_lengths=None, epsilon=0.001, optimize=True, simplify=True, coarsen=False, stop_energy=10.0, num_opt_iter=80, color=None, visible=True, build=False, group=None)[source]#
Not available on a dose; raises TypeError. Build the model from an image’s ROIs instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].add_model('Liver', build=True)
- add_moi(kind, points, view_plane='Axial', position=None, name=None, color=None, visible=True, text=None, group=None)[source]#
Not available on a dose; raises TypeError. Add the markup to an image in the dose’s frame instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].add_moi('line', points)
- add_planeoi(origin, normal, x_axis=None, name=None, extent=None, keep_side=None, group=None, color=None, visible=True)[source]#
Not available on a dose; raises TypeError. Add the plane to an image in the dose’s frame instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].add_planeoi(origin=[0.0, 0.0, 0.0], normal=[0.0, 0.0, 1.0])
- add_poi(poi_name=None, color=None, visible=False, path=None, point=None, match=True, group=None)[source]#
Not available on a dose; raises TypeError. Add the POI to an image in the dose’s frame instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].add_poi('Iso', point=[0.0, -20.0, 15.5])
- add_roi(roi_name=None, color=None, visible=False, path=None, contour=None, plane='Axial', match=True, group=None)[source]#
Not available on a dose; raises TypeError. Add the ROI to an image in the dose’s frame instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].add_roi('Liver', contour=contours)
- compute_dose_on_image(image_name, rigid_name=None, bounds=None)[source]#
Dose (Gy) resampled trilinearly onto an image’s voxel grid, 0 outside the dose grid.
- Parameters:
image_name (str or int) – Image in
Data.image(name or id) whose grid the dose is sampled on.rigid_name (str or int, optional) – Registration in
Data.rigid(name or id) connecting the dose’s frame of reference with the image’s (e.g. planning CT -> CBCT). None = the image is in the dose’s frame of reference.bounds (tuple of int, optional) – (z0, z1, y0, y1, x0, x1) index box on the image grid (end exclusive). None = the whole image.
- Returns:
The image’s shape, or the box’s shape when bounds is given.
- Return type:
(z, y, x) float32 ndarray
Examples
>>> import medicalimageanalysis as mia >>> dose = mia.Data.dose['RTDOSE 01'] >>> on_ct = dose.compute_dose_on_image('CT 01') >>> on_cbct = dose.compute_dose_on_image('CBCT 01', rigid_name='CT 01_CBCT 01') >>> patch = dose.compute_dose_on_image('CT 01', bounds=(40, 60, 200, 300, 150, 260))
- compute_roi_metrics(image_name, roi_names=None, metrics=None, rigid_name=None, partial_volume=True, prescription=None)[source]#
DVH metrics for several ROIs on one image, with the dose resampled once.
The dose is sampled onto the image grid only inside the box that covers every requested ROI, then each ROI’s metrics come from its own partial-volume mask. Voxels are weighted by the fraction inside the contour, so small structures (e.g. parotids) get accurate volumes and dose-volume points.
- Parameters:
image_name (str or int) – Image in
Data.image(name or id) holding the ROIs.roi_names (str, int or list of them, optional) – ROIs on that image, by name or id. None = every ROI on it. ROIs with no contours get NaN.
metrics (str or list of str, optional) –
Metric names (see the module conventions), reported in this order. None =
DEFAULT_METRICS.’Volume’ (cc), ‘Dmin’, ‘Dmax’, ‘Dmean’, ‘Dmedian’, ‘Dstd’ (Gy)
’D<x>’ : dose (Gy) to the hottest x % of the volume, e.g. ‘D95’, ‘D2’
’D<x>cc’ : dose (Gy) to the hottest x cc, e.g. ‘D0.03cc’, ‘D2cc’
’V<x>Gy’ : % of the volume receiving at least x Gy (‘V<x>Gy_cc’ in cc)
’VS<x>Gy’ : % of the volume receiving less than x Gy (‘VS<x>Gy_cc’ in cc)
’V<x>%’ : % of the volume receiving at least x % of the prescription (‘V<x>%_cc’ in cc)
rigid_name (str or int, optional) – Registration in
Data.rigid(name or id) connecting the dose’s frame of reference with the image’s. None = the image is in the dose’s frame of reference.partial_volume (bool, default True) – Weight voxels by the fraction inside the contour. False counts a voxel when at least half of it is inside.
prescription (float, optional) – Prescription dose (Gy), needed for ‘V<x>%’ metrics.
- Returns:
One row per ROI: ‘ROI ID’ (permanent id, for storing results), ‘ROI’ (current name), then the metrics in the requested order.
- Return type:
pandas.DataFrame
- Raises:
ValueError – For an unknown metric name, a ‘V<x>%’ metric without a prescription, or an image in another frame of reference with no (or the wrong) rigid_name.
Examples
>>> import medicalimageanalysis as mia >>> dose = mia.Data.dose['RTDOSE 01'] >>> dose.compute_roi_metrics('CT 01') # every ROI, defaults >>> dose.compute_roi_metrics('CT 01', roi_names=['Parotid_L', 'Parotid_R'], ... metrics=['Dmean', 'D0.03cc', 'V26Gy', 'V30Gy_cc']) >>> dose.compute_roi_metrics('CT 01', roi_names='PTV', metrics=['D95', 'V95%', 'V107%'], prescription=70) >>> dose.compute_roi_metrics('CBCT 01', roi_names=['Parotid_L'], rigid_name='CT 01_CBCT 01')
- create_external(name='External', color=None, visible=False, filepaths=None, threshold=-250)[source]#
Not available on a dose; raises TypeError. Create the external on the planning image instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].create_external()
- create_roi(name=None, color=None, visible=False, filepath=None, group=None)[source]#
Not available on a dose; raises TypeError. Create the ROI on an image in the dose’s frame instead.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].create_roi('GTV')
- get_window()[source]#
[lower, upper] display window from WindowCenter/WindowWidth, else 0 to the maximum dose (Gy).
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.dose['Dose_0'].get_window() [0.0, 72.4]
- class medicalimageanalysis.structure.dose.Display(image)[source]#
Bases:
objectReslicing and view state for one image: slice positions, the shared view rotation and crosshair lines.
Built by
Image(or a subclass such as Dose), not created directly. Each call names its own plane and position, so any number of widgets can share one Display.- Parameters:
image (Image) – The image this display reslices.
- matrix#
Shared view rotation, rebuilt from rotation_totals (Euler ‘xyz’). Identity = native orientation.
- Type:
(3, 3) ndarray
- rotation_totals#
Total rotation about x, y, z in degrees.
- Type:
(3,) ndarray
- rotation_center#
World pivot every plane passes through while rotating.
- Type:
(3,) ndarray
- crosshair#
World point where the crosshair lines cross.
- Type:
(3,) ndarray
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> res = display.compute_array('Axial', display.position['Axial'])
- AXES = {'Axial': (0, 1, 2), 'Coronal': (0, 2, 1), 'Sagittal': (1, 2, 0)}#
- static grid_with_spacing(grid, sx, sy)[source]#
Same corner, axes and physical extent as grid, with a different pixel size.
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> grid = display.get_grid('Axial', display.position['Axial']) >>> fine = mia.Display.grid_with_spacing(grid, 0.5, 0.5)
- compute_array(plane, position, matrix_override=None, rigid_matrix=None, grid=None, as_array=True, as_vtk=False, copy_array=False, force_reslice=False, background=None)[source]#
2D slice of this image for one plane, axis-aligned when possible, otherwise resliced.
- Parameters:
plane (str) – ‘Axial’, ‘Sagittal’ or ‘Coronal’.
position (array_like) – World position (top-left corner) of the slice.
matrix_override ((3, 3) array_like, optional) – View rotation to use instead of the shared
self.matrix.rigid_matrix ((4, 4) array_like, optional) – This image’s native world -> displayed world (e.g.
Rigid.get_display_matrix).grid (dict, optional) – Output pixel grid from another Display’s
get_grid()/grid_with_spacing(). When given, it fully defines the output pixels and this Display only supplies its volume.as_array (bool) – Return the slice as a numpy array, a vtkImageData, or both. Color slices keep their channels in VTK.
as_vtk (bool) – Return the slice as a numpy array, a vtkImageData, or both. Color slices keep their channels in VTK.
copy_array (bool, default False) – Copy the array. The axis-aligned path otherwise returns a view into the volume.
force_reslice (bool, default False) – Always use the reslice kernel, even when a native slice would do.
background (float, optional) – Value outside the volume. None =
image.background(-3001 for images, 0 Gy for a dose). Color always uses 0.
- Returns:
‘dimensions’, ‘spacing’, ‘pixel_spacing’, ‘x_axis’, ‘y_axis’, ‘normal’, ‘origin’, ‘grid’, plus ‘array’ and/or ‘vtk_image’. A slice outside the volume is filled with background (never None).
- Return type:
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> res = display.compute_array('Axial', display.position['Axial']) >>> res = display.compute_array('Coronal', display.position['Coronal'], as_vtk=True)
- compute_plane_geometry(plane, position, matrix_override=None)[source]#
Plane origin (= position, the slice’s top-left corner), view axes and spacing, used to place the output.
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> geometry = display.compute_plane_geometry('Axial', display.position['Axial']) >>> geometry['normal']
- compute_slice_lines(plane, position)[source]#
Crosshair lines of the other two planes on this plane, keyed by plane name (see _intersection_line).
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> lines = display.compute_slice_lines('Axial', display.position['Axial']) >>> lines['Sagittal']['pos'], lines['Sagittal']['angle']
- get_grid(plane, position, matrix_override=None)[source]#
Output pixel grid for this plane: corner, axes, in-plane spacing and shape.
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> grid = display.get_grid('Axial', display.position['Axial']) >>> grid['shape'], grid['sx'], grid['sy']
- go_to_plane(plane, origin, normal, x_axis=None)[source]#
Rotate the shared view so plane lies in a world plane, then scroll every plane through origin.
Used by markups and planes of interest to jump to the view they were drawn on / look straight at a cut. The rotation pivot and the crosshair move to origin. Every plane of this image turns with the shared rotation, so the other two show the target plane edge-on.
- Parameters:
plane (str) – ‘Axial’, ‘Sagittal’ or ‘Coronal’: the view that should lie in the world plane.
origin ((3,) array_like) – World point on the plane; becomes the rotation center and crosshair.
normal ((3,) array_like) – World normal of the plane.
x_axis ((3,) array_like, optional) – In-plane direction the view’s x axis should follow. None keeps the current x axis as close as possible.
- Returns:
The new position (top-left corner) of plane.
- Return type:
(3,) ndarray
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> position = display.go_to_plane('Axial', [10.0, -40.0, 120.0], [0.0, 0.26, 0.97]) >>> res = display.compute_array('Axial', position)
- reset()[source]#
Back to the native orientation: no rotation, pivot and crosshair at the image center, every plane at its initial slice.
Examples
>>> import medicalimageanalysis as mia >>> mia.Data.image['CT 01'].display.reset()
- set_rotation_center(center)[source]#
Set the rotation pivot (a click, ROI centroid, a Rigid’s center, …) and move the crosshair there.
Examples
>>> import medicalimageanalysis as mia >>> image = mia.Data.image['CT 01'] >>> image.display.set_rotation_center(image.roi['Liver'].mesh.center)
- update_rotation(r_x=0, r_y=0, r_z=0, absolute=True)[source]#
Rotate the shared view (every plane) and pivot the crosshair and every plane’s position to match.
- Parameters:
r_x (float) – Degrees about the world x, y, z axes.
r_y (float) – Degrees about the world x, y, z axes.
r_z (float) – Degrees about the world x, y, z axes.
absolute (bool, default True) – True: the angles are the total rotation (e.g. read straight off a slider). False: they are added to the current rotation_totals.
- Returns:
The incremental rotation applied this call (old -> new orientation), for
pivot_position().- Return type:
(3, 3) ndarray
Notes
self.matrix is rebuilt from rotation_totals (Euler ‘xyz’) each call, not accumulated from deltas. Rotations about different axes don’t commute, so accumulating would make the orientation path-dependent; rebuilding keeps (0, 0, 0) the identity.
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> R = display.update_rotation(r_x=0, r_y=0, r_z=15) >>> R = display.update_rotation(r_z=1, absolute=False)
- wheel_position(plane, position, steps=1, main=True)[source]#
Move a slice position along its plane’s normal by a number of scroll steps (one voxel each).
main=True also stores it as this plane’s position and moves the crosshair with it.
Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> new_position = display.wheel_position('Axial', display.position['Axial'], steps=-3)
- pivot_position(position, R)[source]#
Rotate one widget’s position about rotation_center by R (the value returned by
update_rotation()).update_rotation already moves
self.position; use this for positions the caller keeps itself.Examples
>>> import medicalimageanalysis as mia >>> display = mia.Data.image['CT 01'].display >>> R = display.update_rotation(r_z=5) >>> widget_position = display.pivot_position(widget_position, R)