utils.measurements2D_utils

This module contains the Measurements2DMixin class, which is used to perform 2D measurements on lesions in medical images. The class provides methods for calculating, displaying, and managing lesion measurements, as well as handling user interactions with the GUI.

Classes

Measurements2DMixin

This mixin class provides methods for performing 2D measurements on lesions in medical images.

LineNodePair

A class that represents a pair of line nodes for a lesion in a timepoint. The class inherits from list to allow

LineNodePairList

A list of LineNodePair objects. This class inherits from list to allow easy access to the line node pairs.

Module Contents

class utils.measurements2D_utils.Measurements2DMixin[source]

This mixin class provides methods for performing 2D measurements on lesions in medical images. It includes methods for calculating, displaying, and managing lesion measurements, as well as handling user interactions with the GUI.

instance_segmentations_matched = None

List of instance segmentations (numpy arrays) with matching labels across time points.

resampledSegNodes = None

List of segmentation nodes (vtkMRMLSegmentationNode) containing the matched instance segmentations.

resampledVolumeNodes = None

List of instance segmentations (vtkMRMLLabelMapVolumeNode) transformed and resampled to the reference input volume space.

previous_timepoint_orientation

Dictionary to store the orientation of the lesions in the previous timepoint to enable consistent 2D measurement orientation across timepoints.

previous_timepoint_center

Dictionary to store the center of the lesions in the previous timepoint to enable consistent 2D measurement slices across timepoints.

observations = []

Store observers for the line nodes to handle user interactions.

observations2 = []

Store observers for the line nodes to handle user interactions.

onCalc2DButton()[source]

This method is called when the “Calculate 2D” button is pressed.

It performs the following steps: 1. Get the selected segmentations and instance segmentations. 2. Match the instance segmentations across timepoints. 3. Transform and resample the instance segmentations in the original reference image space. 4. For each timepoint and lesion, place the RANO lines. 5. Evaluate the 2D measurements and store the results in a dictionary. 6. Display the results in the UI. 7. Update the line pair UI list. 8. Calculate the results table.

onToggleShowInstanceSegButton()[source]

This method is called when the “Show/Hide Lesions” button is pressed. It shows or hides the lesions in the slice views based on the resampled labelmap volumes. In the 3D views they are shown based on the resampled segmentation nodes (because the resampled labelmap volumes are not displayed smoothly in 3D, but voxelized).

onAddLinePairButton(timepoint)[source]

This method is called when the “Add Lines t1” or “Add Lines t2” button is pressed. It allows the user to add a new line pair for the selected timepoint by placing two lines in the slice views of the corresponding timepoint. The lines are added to the lineNodePairs list and displayed in the UI. :param timepoint: the timepoint for which the line pair is added (e.g., “timepoint1” or “timepoint2”)

update_linepair_ui_list()[source]

This method updates the UI list of line pairs by populating the table with the lesion index, timepoint, and whether the lesion is enhancing, measurable, and target. It also sets the background color of the rows such that rows of the same lesion index are grouped together for better readability.

coords_ijk_to_world(coords_ijk, node)[source]

Convert the coordinates from IJK to world coordinates.

static setViews(node, timepoint)[source]

Set the views for the line node pair such that the lines are only shown in the views corresponding to the timepoint and the line orientation (sagittal, coronal, axial) of the line pair.

static centerTimepointViewsOnFirstMarkupPoint(lineNode, tp)[source]

Center the slice views and cameras on the first markup point of the line node. :param lineNode: the line node to center on :param tp: the timepoint to center on (e.g., “timepoint1” or “timepoint2”)

static centerTimepointViewsOnCenterPoint(lineNodePair, tp)[source]

Center the slice views and cameras on the center point of the line node pair. :param lineNodePair: the line node pair to center on :param tp: the timepoint to center on (e.g., “timepoint1” or “timepoint2”)

class utils.measurements2D_utils.LineNodePair(lesion_idx, timepoint, enhancing=True, measurable=True, target=False)[source]

Bases: list

A class that represents a pair of line nodes for a lesion in a timepoint. The class inherits from list to allow easy access to the line nodes. The class also contains methods to create the line nodes, set and get their coordinates, and set the views for the line nodes. The class also contains methods to create a fiducial node for the text label of the line nodes and to handle events when the line nodes are modified. The class also contains methods to set the enhancing, measurable, and target properties of the line nodes.

Parameters:
  • lesion_idx – the index of the lesion

  • timepoint – the timepoint for which the line nodes are created (e.g., “timepoint1” or “timepoint2”)

  • enhancing – whether the lesion is enhancing or not (default: True)

  • measurable – whether the lesion is measurable or not (default: True)

  • target – whether the lesion is a target lesion or not (default: False)

lesion_idx

Lesion index

timepoint

Timepoint for which the line node pair is created

enhancing = True

Whether the lesion is enhancing or not

measurable = True

Whether the lesion is measurable or not

target = False

Whether the lesion is a target lesion or not

fiducialNodeForText

Fiducial node for the text label of the line nodes

observations = []

List of observers for the line nodes

set_coords(coords)[source]

Set the coordinates of the line nodes to the given world coordinates.

get_coords()[source]

Get the coordinates of the line nodes in world coordinates.

get_line_lengths()[source]

Get the lengths of the lines in world coordinates.

get_line_length_product()[source]

Get the product of the lengths of the lines in world coordinates.

static create_twoLineNodes(les_idx, timepoint)[source]

Create two line nodes for the line pair and set their properties. :param les_idx: the index of the lesion :param timepoint: the timepoint for which the line nodes are created (e.g., “timepoint1” or “timepoint2”)

create_fiducialNodeFor_text()[source]

Create a fiducial node for the text label of the line nodes.

static set_color_depending_on_orthogonality(n, e, lineNode1, lineNode2, fiducialNodeForText=None)[source]

Set the color of the lines depending on whether they are orthogonal or not. :param n: the event name :param e: the event object :param lineNode1: the first line node :param lineNode2: the second line node :param fiducialNodeForText: the fiducial node for the text label of the line nodes

annotate_with_text()[source]

Annotate the line nodes with the length of the lines in world coordinates.

uponLineNodeModifiedEvent(n, e)[source]

This method is called when the line nodes are modified. It sets the color of the lines depending on whether they are orthogonal or not and updates the text label of the line nodes with the length of the lines in world coordinates. :param n: the event name :param e: the event object

cleanup()[source]

Cleanup the line node pair by removing the observers and the fiducial node.

__repr__()[source]

Return repr(self).

class utils.measurements2D_utils.LineNodePairList[source]

Bases: list

A list of LineNodePair objects. This class inherits from list to allow easy access to the line node pairs. The class also contains methods to add, remove, and modify the line node pairs. The class also contains methods to update the UI and the response assessment based on the line node pairs.

__delitem__(index)[source]

Makes sure that line nodes contained in the LineNodePairList are removed from the scene when removed from the list

pop(index)[source]

Makes sure that line nodes contained in the LineNodePairList are removed from the scene when popped from the list

uponModified()[source]

This method is called when the line node pairs are modified. It updates the UI and the response assessment based on the line node pairs.

custom_sort(*args, **kwargs)[source]

Sort the list of LineNodePair objects and return a new LineNodePairList object.

decide_enhancing()[source]

Logic to decide whether the lesion is enhancing or not. For now, all lesions are considered enhancing initially.

decide_measurable()[source]

Decide whether the lesion is measurable or not based on the orthogonal lines.

decide_target(strategy='two_largest_enhancing')[source]

Logic to decide whether the lesion is a target lesion or not. The strategy can be one of the following: - “two_largest_enhancing”: select the two largest enhancing lesions from the baseline - “three_largest_enhancing”: select the three largest enhancing lesions from the baseline - “two_largest_enhancing_and_two_largest_non_enhancing”: select the two largest enhancing lesions and the two

largest non-enhancing lesions from the baseline

Parameters:

strategy – the strategy to use for selecting the target lesions

get_number_of_targets()[source]

Get the number of target lesions, but don’t count the same lesion twice it is in the list twice (for both timepoints)

get_number_of_new_target_lesions()[source]

Get the number of new target lesions that were not target lesions at the first timepoint but appeared at the second

get_number_of_disappeared_target_lesions()[source]

Get the number of target lesions that were target lesions at the previous timepoints but are not target lesions because they disappeared

get_number_of_new_measurable_lesions()[source]

Get the number of new measurable lesions that were not measurable at the first timepoint but appeared at the second

get_sum_of_bidimensional_products(timepoint)[source]

Given a list of line node pairs, this function returns the sum of bidimensional products of the orthogonal lines of all lesions at the given timepoint.

get_rel_area_change()[source]

Given a list of line node pairs, this function returns the relative change of the sum of bidimensional products of the orthogonal lines of all lesions at timepoint 2 relative to the sum of the bidimensional products of the orthogonal lines of all lesions at timepoint 1.