osirix.roi
Functionality for the regions of interest in 2D (ROI
) and 3D (ROIVolume
) viewers.
The following ROI
types are available in pyOsiriX, seperated into 2 core groups:
-
Brush ROIs: Described by a 2D array of boolean values (0 = outside ROI, 1 = within ROI).
- tPlain: The only brush ROI type.
-
Point-based ROIs: Described by a set of N 2-element vertices as a shape (N, 2) array.
- tMeasure: A ruler measurement. N = 2.
- tROI: A square ROI. N = 4. Created by rectangle.
- tOval: An oval-based ROI. No limit on N. Created by rectangle.
- tOPolygon: An open polygon. No limit on N.
- tCPolygon: A closed polygon. No limit on N.
- tAngle: An angle measurement. N = 3.
- tText: A text box. Created by rectangle.
- tArrow: An arrow. N = 2 (arrow head then tail).
- tPencil: A closed polygon. No limit it N.
- t2DPoint: A single point ROI. Created by rectangle.
- tAxis: An axis-based ROI for bi-dimensional measurement. N = 4.
- tDynAngle: The angle between two lines. N = 4.
- tTAGT: A pair of oriented perpendicular lines for measuring distance. N = 6.
- tBall: A circular ROI representing a slice of a 3D ball ROI. No limit on N. It is not possible to create a new tBall ROI with pyOsiriX.
- tOvalAngle: An oval with an additional angle specifier. No limit on N. Created by rectangle.
Example usage
import osirix
import matplotlib.pyplot as plt
viewer = osirix.frontmost_viewer() # Raises GrpcException error if no viewer is available.
rois = viewer.selected_rois() # Get the currently selected ROI object.
if len(rois) == 0:
raise ValueError("No ROIs found.")
roi = rois[0]
roi_type = roi.itypes()[roi.itype] # Get the selected ROI type.
if roi_type == "tPlain":
raise ValueError("Cannot plot mask (brush) ROI vertices")
plt.plot(roi.points[:, 0], roi.points[:, 1], "ko") # Plot the ROI vertices.
plt.show()
ROI
Bases: OsirixBase
Represents a single region of interest in a 2D viewer (ViewerController
)
color: Tuple[int, int, int]
property
writable
The color of the volume ROI as a (r, g, b) tuple (each channel in range 0-255)
itype: int
property
The ROI type as an integer
name: str
property
writable
The name of the ROI
opacity: float
property
writable
The opacity of the ROI, ranging from 0 (transparent) to 1 (opaque)
pix: osirix.dcm_pix.DCMPix
property
The DCMPix instance coupled with the ROI. This should be the one on which it is drawn.
points: NDArray
property
writable
The vertices of any polygon-based ROI. An array with shape [N, 2].
stype: str
property
The type of the ROI as a string
thickness: float
property
writable
The line thickness (in points) of any polygon-based ROI.
centroid()
The centroid of the ROI in format (column, row). Non-integer values are permitted.
delete()
Delete the ROI. This cannot be undone!
flip_horizontally()
Flip the ROI horizontally
flip_vertically()
Flip the ROI vertically
itypes(reverse_order=False)
classmethod
A map between the integer ROI type (itype) and a text descriptor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reverse_order |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
Dict
|
A mapping between ROI itype and textual descriptor. |
roi_area()
The area of the ROI in squared centimeters.
roi_move(columns, rows)
Move the ROI by a specified number of columns and rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns |
int
|
The number of columns to move. positive = left → right, negative = right → left. |
required |
rows |
int
|
The number of rows to move. positive = downwards, negative = upwards. |
required |
rotate(theta, center=None)
Rotate the ROI by angle theta, about a given
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
float
|
The angle by which to rotate (in degrees). Positive is clockwise. |
required |
center |
Tuple[float, float]
|
The position (column, row) about which to rotate.
These can be non-integer values. If |
None
|
ROIVolume
Bases: OsirixBase
Represents a single volumetric region of interest in a 3D viewer (VRController
)
color: Tuple[float, float, float]
property
writable
The color of the volume ROI as a (r, g, b) tuple (each channel in range 0-1)
factor: float
property
writable
The factor of the ROI volume in the range 0-1
name: str
property
The name of the ROI volume.
opacity: float
property
writable
The opacity of the ROI volume in the range 0-1
texture: bool
property
writable
Whether the volume ROI is textured
visible: bool
property
writable
Whether the volume ROI is visible in the 3D viewer
vr_controller: osirix.vr_controller.VRController
property
The 3D volume render window in which this ROI is shown.
volume()
The volume of the ROI
Returns:
Type | Description |
---|---|
float
|
The volume of the 3D ROI (in millilitres). |