platipy.imaging.label package#

Submodules#

platipy.imaging.label.comparison module#

platipy.imaging.label.comparison.compute_apl(label_ref, label_test, distance_threshold_mm=3)#

helper function for computing the added path length

Parameters:
  • label_ref (sitk.Image) – The reference (ground-truth) label

  • label_test (sitk.Image) – The test label

  • distance_threshold_mm (float) – Distances under this threshold will not contribute to the added path length

Returns:

The total (slice-wise) added path length in mm

Return type:

float

platipy.imaging.label.comparison.compute_metric_dsc(label_a, label_b, auto_crop=True)#

Compute the Dice Similarity Coefficient between two labels

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

The Dice Similarity Coefficient

Return type:

float

platipy.imaging.label.comparison.compute_metric_hd(label_a, label_b, auto_crop=True)#

Compute the Hausdorff distance between two labels

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

The maximum Hausdorff distance

Return type:

float

platipy.imaging.label.comparison.compute_metric_masd(label_a, label_b, auto_crop=True)#

Compute the mean absolute distance between two labels

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

The mean absolute surface distance

Return type:

float

platipy.imaging.label.comparison.compute_metric_mean_apl(label_ref, label_test, distance_threshold_mm=3)#

Compute the mean (slice-wise) added path length in mm

This operates on transaxial slices, which are assumed to be in the z-dimension (axis=2).

Parameters:
  • label_ref (sitk.Image) – The reference (ground-truth) label

  • label_test (sitk.Image) – The test label

  • distance_threshold_mm (float) – Distances under this threshold will not contribute to the added path length

Returns:

The mean (slice-wise) added path length in mm

Return type:

float

platipy.imaging.label.comparison.compute_metric_sensitivity(label_a, label_b, auto_crop=True)#

Compute the sensitivity between two labels

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

The sensitivity between the two labels

Return type:

float

platipy.imaging.label.comparison.compute_metric_specificity(label_a, label_b, auto_crop=True)#

Compute the specificity between two labels

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

The specificity between the two labels

Return type:

float

platipy.imaging.label.comparison.compute_metric_total_apl(label_ref, label_test, distance_threshold_mm=3)#

Compute the total (slice-wise) added path length in mm

This operates on transaxial slices, which are assumed to be in the z-dimension (axis=2).

Parameters:
  • label_ref (sitk.Image) – The reference (ground-truth) label

  • label_test (sitk.Image) – The test label

  • distance_threshold_mm (float) – Distances under this threshold will not contribute to the added path length

Returns:

The total (slice-wise) added path length in mm

Return type:

float

platipy.imaging.label.comparison.compute_surface_dsc(label_a, label_b, tau=3.0)#

Compute Surface Dice

From: Nikolov S et al. Clinically Applicable Segmentation of Head and Neck Anatomy for Radiotherapy: Deep Learning Algorithm Development and Validation Study J Med Internet Res 2021;23(7):e26151, DOI: 10.2196/26151

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

  • tau (float) – Accepted deviation between contours (in mm)

Returns:

The Surface DSC between the two labels

Return type:

float

platipy.imaging.label.comparison.compute_surface_metrics(label_a, label_b, verbose=False)#

Compute surface distance metrics between two labels. Surface metrics computed are: hausdorffDistance, hausdorffDistance95, meanSurfaceDistance, medianSurfaceDistance, maximumSurfaceDistance, sigmaSurfaceDistance, surfaceDSC

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

  • verbose (bool, optional) – Whether to print verbose output. Defaults to False.

Returns:

Dictionary object containing surface distance metrics

Return type:

dict

platipy.imaging.label.comparison.compute_volume(label)#

Computes the volume in cubic centimetres

Parameters:

label (SimpleITK.Image) – A binary mask.

Returns:

The volume (in cubic centimetres)

Return type:

float

platipy.imaging.label.comparison.compute_volume_metrics(label_a, label_b)#

Compute volume metrics between two labels. Volume metrics computed are: DSC, volumeOverlap fractionOverlap truePositiveFraction trueNegativeFraction falsePositiveFraction falseNegativeFraction

Parameters:
  • label_a (sitk.Image) – A mask to compare

  • label_b (sitk.Image) – Another mask to compare

Returns:

Dictionary object containing volume metrics

Return type:

dict

platipy.imaging.label.fusion module#

platipy.imaging.label.fusion.combine_labels(atlas_set, structure_name, label='DIR', threshold=0.0001, smooth_sigma=1.0)#

Combine labels using weight maps

platipy.imaging.label.fusion.combine_labels_staple(label_list_dict, threshold=0.0001)#

Combine labels using STAPLE

platipy.imaging.label.fusion.compute_weight_map(target_image, moving_image, vote_type='unweighted', vote_params={'blockSize': 5, 'correlation_function': <function <lambda>>, 'epsilon': 1e-05, 'factor': 1000000000000.0, 'gain': 6, 'normalise': False, 'patch_window_mm': 25, 'resampled_voxel_size_mm': 3, 'sigma': 2.0})#

Computes the weight map

platipy.imaging.label.fusion.mutual_information(arr_a, arr_b, bins=64)#

Computes the (histogram-based) mutual information between two arrays

Parameters:
  • arr_a (np.ndarray) – The first image array values, should be flattened to a 1D array.

  • arr_b (np.ndarray) – The second image array values, should be flattened to a 1D array.

  • bins (np.ndarray | int, optional) – Histogram bins. Passed directly to np.histogram2d, so any format accepted by this function is okay. Defaults to 64.

Returns:

The mutual information between the arrays.

Return type:

float

platipy.imaging.label.fusion.process_probability_image(probability_image, threshold=0.5)#

Generate a mask given a probability image, performing some basic post processing as well.

platipy.imaging.label.iar module#

platipy.imaging.label.iar.gaussian_curve(x, a, m, s)#

Returns a Gaussian (normal) curve

Parameters:
  • x (np.ndarray) – values to sample the normal curve

  • a (float) – magnitude

  • m (float) – location (mean)

  • s (float) – scale (standard deviation)

Returns:

sampled values along the normal curve

Return type:

np.ndarray

platipy.imaging.label.iar.median_absolute_deviation(data, axis=None)#

Median Absolute Deviation: a “Robust” version of standard deviation. Indices variabililty of the sample. https://en.wikipedia.org/wiki/Median_absolute_deviation

platipy.imaging.label.iar.run_iar(atlas_set, reference_structure, smooth_distance_maps=False, smooth_sigma=1, z_score_statistic='MAD', outlier_method='IQR', min_best_atlases=10, outlier_factor=1.5, iteration=0, single_step=False, project_on_sphere=False, label='DIR')#

Perform iterative atlas removal on the atlas_set

platipy.imaging.label.projection module#

platipy.imaging.label.projection.evaluate_distance_on_surface(reference_volume, test_volume, abs_distance=True, reference_as_distance_map=False)#

Evaluates a distance map on a surface Input: reference_volume: binary volume SimpleITK image, or alternatively a distance map

test_volume: binary volume SimpleITK image

Output: theta, phi, values

platipy.imaging.label.projection.evaluate_distance_to_reference(reference_volume, test_volume, resample_factor=1)#

Evaluates the distance from the surface of a test volume to a reference Input: reference_volume: binary volume SimpleITK image

test_volume: binary volume SimpleITK image

Output: values : the distance to each point on the reference volume surface

platipy.imaging.label.projection.regrid_spherical_data(theta, phi, values, resolution)#

Re-grids spherical data Input: theta, phi, values Options: plot a figure (plotFig), save a figure (saveFig), case identifier (figName) Output: p_lat, p_long, grid_values (, fig)

platipy.imaging.label.utils module#

platipy.imaging.label.utils.binary_decode_image(binary_encoded_img)#

Decode a binary label map to a list of structures.

Parameters:

binary_encoded_img (SimpleITK.Image) – The encoded image.

Returns:

The list of images.

Return type:

list (SimpleITK.Image)

platipy.imaging.label.utils.binary_encode_structure_list(structure_list)#

Encode a list of binary labels using binary encoding

Parameters:

structure_list (list (SimpleITK.Image)) – The list of binary label maps.

Raises:

ValueError – A maximum of 32 structures can be encoded!

Returns:

The encoded image, can be saved etc. as usual.

Return type:

SimpleITK.Image

platipy.imaging.label.utils.correct_volume_overlap(binary_label_dict, assign_overlap_to_largest=True)#

Label structures by primes Smallest prime = largest volume

platipy.imaging.label.utils.generate_primes()#

Generate an infinite sequence of prime numbers.

platipy.imaging.label.utils.get_com(label, as_int=True, real_coords=False)#

Get centre of mass of a SimpleITK.Image

Parameters:
  • label (sitk.Image) – Label mask image.

  • as_int (bool, optional) – Returns each components as int if true. Defaults to True.

  • real_coords (bool, optional) – Return coordinates in physical space if true. Defaults to False.

Returns:

List of coordinates

Return type:

list

platipy.imaging.label.utils.prime_decode_image(prime_encoded_image)#

Decode a prime-encoded image

Parameters:

prime_encoded_image (SimpleITK.Image) – A prime-encoded image.

Returns:

A list of binary masks.

Return type:

list [SimpleITK.Image]

platipy.imaging.label.utils.prime_encode_structure_list(structure_list)#

Encode a list of structures using prime labels

Parameters:

structure_list (list [SimpleITK.Image]) – A list of binary masks.

Returns:

The prime-encoded structure

Return type:

SimpleITK.Image

platipy.imaging.label.utils.vectorised_transform_index_to_physical_point(image, point_array, rotate=True)#

Transforms a set of points from array indices to real-space

platipy.imaging.label.utils.vectorised_transform_physical_point_to_index(image, point_array, rotate=True)#

Transforms a set of points from real-space to array indices

Module contents#