Skip to content

osirix.viewer_controller

Functionality for the 2D viewer.

Example usage
import osirix

viewer = osirix.frontmost_viewer()  # Raises GrpcException error if no viewer is available.
n_slices = len(viewer.pix_list(0))  # pix_list(n) returns array of DCMPix instances for nth frame.
viewer.idx = int(n_slices / 2)  # Move display to the central slice.
viewer.wlww = (50, 100)  # Set the displayed window level and width..
viewer.needs_display_update()  #Get the viewer to re-draw itself.

ViewerController

Bases: OsirixBase

Represents one of the displayed volume render windows.

displayed_idx: int property writable

The data slice index currently being displayed to the viewer (starting at 0).

Note that this may not be equal to the index displayed on the viewer when data_flipped is True.

flipped_data: int property

Whether the slices data are flipped in the viewer.

idx: int property writable

The slice index currently being displayed to the viewer (starting at 0).

Note that the index displayed on the viewer is this value plus one.

max_movie_index: int property

The maximum movie index in the viewer.

modality: str property

The modality of the displayed data.

movie_idx: int property writable

The frame currently being displayed by the viewer.

title: str property

The title of the 2D viewing window.

wlww: Tuple[float, float] property writable

The window level and window width of the viewer.

blending_controller()

Return the viewer controller instance that is being fused with this one.

Returns:

Type Description
ViewerController

The blending viewer instance.

Example usage
frontmost_viewer = osirix.frontmost_viewer()
blending_controller = frontmost_viewer.blending_controller()

close()

Close the viewer.

Note: This will close any associated viewers (e.g. VRControllers).

close_viewer()

Close the viewer

copy_viewer_window()

Create a copy of the viewer.

This can be useful for image processing when you want to keep a copy of the original and a processed version.

Returns:

Type Description
ViewerController

The new osirix.viewer_controller.ViewerController instance.

Example usage
frontmost_viewer = osirix.frontmost_viewer()
acopy = frontmost_viewer.copy_viewer_window()

cur_dcm()

Return the currently displayed DCMPix instance.

Returns:

Type Description
DCMPix

The currently displayed DCMPix instance.

Example usage
frontmost_viewer = osirix.frontmost_viewer()
pix = frontmost_viewer.cur_dcm()

fuse_with_viewer(viewer)

Fuse another viewer onto this one.

Parameters:

Name Type Description Default
viewer ViewerController

The viewer to fuse onto the present one.

required
Example usage
frontmost_viewer = osirix.frontmost_viewer()
frontmost_viewer.fuse_with_viewer(another_viewer_controller)

is_data_volumic(in_4d=False)

Does the underlying data have sufficient geometric properties for volume rendering.

Parameters:

Name Type Description Default
in_4d bool

Determine for all frames.

False

Returns:

Type Description
bool

Is the data volumic?

needs_display_update()

Tell the viewer it should update its display.

This is particularly important if you want to see changes to pixel values in real time.

new_angle_roi(p1, p2, p3, **kwargs)

Create a new angle ROI within the viewer.

This draws two connected vectors:

- v = p2 → p1
- u = p2 → p3

The displayed angle is the angle between these two vectors.

Parameters:

Name Type Description Default
p1 (float, float)

The (column, row) position of the first angle vertex.

required
p2 (float, float)

The (column, row) position of the second angle vertex.

required
p3 (float, float)

The (column, row) position of the third angle vertex.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_arrow_roi(tail, head, **kwargs)

Create a new text-box ROI within the viewer.

Parameters:

Name Type Description Default
tail (float, float)

The (column, row) position of the arrow tail.

required
head (float, float)

The (column, row) position of the arrow hear.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_axis_roi(p1, p2, p3, p4, **kwargs)

Create a new axis ROI within the viewer.

Parameters:

Name Type Description Default
p1 (float, float)

The (column, row) position of the first vertex.

required
p2 (float, float)

The (column, row) position of the second vertex.

required
p3 (float, float)

The (column, row) position of the third vertex.

required
p4 (float, float)

The (column, row) position of the fourth vertex.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_dynamic_angle_roi(p1, p2, p3, p4, **kwargs)

Create a new dynamic angle ROI within the viewer.

This draws two vectors:

- v = p2 → p1
- u = p3 → p4

The displayed angle is the angle between these two vectors. The vector p2 -> p3 is also drawn.

Parameters:

Name Type Description Default
p1 (float, float)

The (column, row) position of the first angle vertex.

required
p2 (float, float)

The (column, row) position of the second angle vertex.

required
p3 (float, float)

The (column, row) position of the third angle vertex.

required
p4 (float, float)

The (column, row) position of the fourth angle vertex.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_mask_roi(buffer, **kwargs)

Create a new mask ROI within the viewer.

Parameters:

Name Type Description Default
buffer NDArray

The buffer mask as a 2D boolean Numpy array.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_measurement_roi(start, end, **kwargs)

Create a new length measurement ROI within the viewer.

Parameters:

Name Type Description Default
start (float, float)

The starting position of the ROI (column, row).

required
end (float, float)

The ending position of the ROI (column, row).

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_oval_angle_roi(center, width, height, **kwargs)

Create a new angle oval ROI within the viewer.

Note: At present we are not aware that it is possible to pre-determine the angle part of this ROI. This method defines only the oval that will be drawn; the angle appears to have a default value of 113 degrees that can then be adapted by the user.

Parameters:

Name Type Description Default
center (float, float)

The (column, row) center of the oval ROI.

required
width float

The width of the oval ROI.

required
height float

The height of the oval ROI.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_oval_roi(center, width, height, **kwargs)

Create a new oval ROI within the viewer.

Parameters:

Name Type Description Default
center (float, float)

The (column, row) center of the oval ROI.

required
width float

The width of the oval ROI.

required
height float

The height of the oval ROI.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_point_roi(column, row, **kwargs)

Create a new 2D point ROI within the viewer.

Parameters:

Name Type Description Default
column float

The column position of the ROI

required
row float

The row position of the ROI

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_polygon_roi(points, closed=True, **kwargs)

Create a new polygon ROI within the viewer.

Parameters:

Name Type Description Default
points NDArray

The vertices of the ROI. Must have shape (N, 2).

required
closed bool

Whether the polygon is closed.

True
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_rectangle_roi(center, width, height, **kwargs)

Create a new rectangle ROI within the viewer.

Parameters:

Name Type Description Default
center (float, float)

The (column, row) center of the rectangle ROI.

required
width float

The width of the rectangle ROI.

required
height float

The height of the rectangle ROI.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_roi(itype=15, name='', idx=0, movie_idx=0, buffer_position_column=0, buffer_position_row=0, color=(0, 255, 0), thickness=1.0, opacity=1.0, buffer=None, rect=None, points=None)

Create a new ROI within the viewer.

Important: It is safer to create a new ROI using one of the utility functions as they provide better checking on input parameters in certain contexts, and ensure the right ROI type is created. This is meant as a parent function that performs the heavy lifting. It is made public for transparency.

Parameters:

Name Type Description Default
itype int

The index of the roi type (see osirix.roi.ROI.itypes for details).

15
name str

The name of the ROI.

''
idx int

The slice index on which to create the new ROI.

0
movie_idx int

The frame on which to create the new ROI.

0
buffer_position_column int

The column offset of a mask ROI in pixel coordinates.

0
buffer_position_row int

The row offset of a mask ROI in pixel coordinates.

0
color tuple

The RGB color of the ROI (values from 0-255 in each channel).

(0, 255, 0)
thickness float

The thickness of the ROI. Value between 1-20 as per OsiriX.

1.0
opacity float

The opacity on a scale from 0 (transparent) to 1 (opaque).

1.0
buffer NDArray

The buffer mask as a 2D boolean Numpy array. If None, then ignored.

None
rect NDArray

The rectangle defining the ROI. Must be shape (4,).

None
points NDArray

The points defining the ROI. Must be shape (N, 2) for N vertices. If None or buffer is not None or rect is not None then ignored.

None

Returns:

Type Description
ROI

The created ROI instance.

Raises:

Type Description
ValueError

When buffer, points and rect are all None.

ValueError

When the input data is of invalid format.

new_tagt_roi(a, b, c, d, **kwargs)

Create a new tTAGT ROI within the viewer.

ROI displays:

- The length of vector DA.
- The perpendicular distance from B to DA
- The perpendicular distance from C to DA
- The distance between B and C, parallel to DA.

Parameters:

Name Type Description Default
a (float, float)

The (column, row) position of point A.

required
b (float, float)

The (column, row) position of point B.

required
c (float, float)

The (column, row) position of point C.

required
d (float, float)

The (column, row) position of point D.

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

new_text_roi(column, row, name, **kwargs)

Create a new text-box ROI within the viewer.

Parameters:

Name Type Description Default
column float

The column position of the ROI

required
row float

The row position of the ROI

required
name str

The text to show

required
**kwargs

See new_roi for all additional parameters.

{}

Returns:

Type Description
ROI

The created ROI instance.

open_vr_viewer(mode='VR')

Open a new 3D viewer for the enclosed data.

Parameters:

Name Type Description Default
mode str

Either 'VR' for volume render, or 'MIP' for a maximum intensity projection.

'VR'

Returns:

Type Description
VRController

A VRController instance.

Example usage
frontmost_viewer = osirix.frontmost_viewer()
vr_controller = frontmost_viewer.open_vr_viewer(mode="VR")

pix_list(movie_idx=None)

Access the list of DCMPix objects contained within the 2D viewer.

Parameters:

Name Type Description Default
movie_idx int

The frame from which to extract the DCMPix instances. If None, then use the currently displayed movie_idx.

None

Returns:

Type Description
List[DCMPix]

The list of osirix.dcm_pix.DCMPix instances requested for a particular frame.

resample_viewer_controller(vc)

Resample this (moving) ViewerController based on another (fixed) ViewerController.

Note that the original moving viewer is closed, so a reference to the new one is returned. This means it is generally advised to the call the method in the following manner:

moving_viewer = moving_viewer.resample_viewer_controller(fixed_viewer)

Parameters:

Name Type Description Default
vc ViewerController

The fixed viewer.

required

Returns:

Type Description
ViewerController

The resampled viewer window.

roi_list(movie_idx=None)

Access a list of lists of ROI objects contained within the 2D viewer.

The length of the outer list is the same as the number of slices in the viewer. Note that some inner lists will be empty if no ROIs are drawn on that slice.

Parameters:

Name Type Description Default
movie_idx int

The frame from which to extract the ROI instances. If None, then use the currently displayed movie_idx.

None

Returns:

Type Description
List[List[ROI]]

A list of lists of osirix.roi.ROI instances requested for a particular frame.

rois_with_name(name, movie_idx=None, in_4d=False)

Return a list of ROIs with a given name. Args: name (str): The name of ROIs to look for. movie_idx (int): The frame from which to extract the ROI instances. If None, then use the currently displayed movie_idx. in_4d (bool): Whether to look through all frames.

Returns:

Type Description
List[ROI]

A list of ROIs with the given name.

selected_rois()

Return a list of the user-selected ROIs

Returns:

Type Description
List[ROI]

A list of selected ROIs.

vr_controllers()

Return the list of currently displayed 3D viewers associates with this 2D window.

Returns:

Type Description
List[VRController]

Any VRController instances associated with this 2D window.

Example usage
frontmost_viewer = osirix.frontmost_viewer()
vr_controllers = frontmost_viewer.vr_controllers()