platipy.imaging.utils package#
Submodules#
platipy.imaging.utils.crop module#
Various useful utility functions for atlas based segmentation algorithms.
- platipy.imaging.utils.crop.crop_to_label_extent(image, label, expansion_mm=0)#
Crop an image to the 3D extent defined by a binary mask (label).
- Parameters:
image (SimpleITK.Image) – The image to crop.
label (SimpleITK.Image) – The binary mask (label) defining the region to crop to.
expansion_mm (float | tuple | list, optional) – An optional expansion in physical units. Can be defined as a single number or iterable: (axial, coronal, sagittal) expansion. Defaults to 0.
- Returns:
The cropped image.
- Return type:
SimpleITK.Image
- platipy.imaging.utils.crop.crop_to_roi(image, size, index)#
Utility function for cropping images
- platipy.imaging.utils.crop.label_to_roi(label, expansion_mm=[0, 0, 0], return_as_list=False)#
Generates a region of interest (ROI), defined by a starting index (z,y,x) and size (s_z, s_y, s_x). This can be used to crop images/labels.
- Parameters:
label (sitk.Image | list) – Binary label image/mask/structure to define to ROI
expansion_mm (list, optional) – An optional expansion of the box (in each direciton). Defaults to [0, 0, 0].
- Returns:
crop_box_size, crop_box_starting_index
- Return type:
tuple
platipy.imaging.utils.lung module#
- platipy.imaging.utils.lung.detect_holes(img, lower_threshold=-10000, upper_threshold=-400)#
Detect all (air) holes in given image. Default threshold values given are defined for CT.
- Parameters:
img (sitk.Image) – The image in which to detect holes.
lower_threshold (int, optional) – The lower threshold of intensities. Defaults to -10000.
upper_threshold (int, optional) – The upper threshold of intensities. Defaults to -400.
- Returns:
image containing labels of all holes detected labels: a list of holes detected and some of their properties
- Return type:
label_image
- platipy.imaging.utils.lung.fill_holes(img, label_image, external_mask, lung_mask, fill_value=50)#
Returns the input image with all holes filled (except for the external and lung holes).
- Parameters:
img (sitk.Image) – The image to fill
label_image (sitk.Image) – Label image from detect_holes
external_mask (sitk.Image) – The external mask of the patient.
lung_mask (sitk.Image) – The lung mask of the patient.
fill_value (int) – The value to use to fill the holes. Defaults to 50.
- Returns:
The image with holes filled
- Return type:
sitk.Image
- platipy.imaging.utils.lung.get_external_mask(label_image, labels, kernel_radius=5)#
Get a External mask given a label image and labels computed with detect_holes
- Parameters:
label_image (sitk.Image) – Label image from detect_holes
labels (list) – List of labels from detect_holes
kernel_radius (int, optional) – The width of the radius used by binary close. Defaults to 5.
- Returns:
External mask
- Return type:
sitk.Image
- platipy.imaging.utils.lung.get_lung_mask(label_image, labels, kernel_radius=2)#
Get a Lung mask given a label image and labels computed with detect_holes
- Parameters:
label_image (sitk.Image) – Label image from detect_holes
labels (list) – List of labels from detect_holes
kernel_radius (int, optional) – The width of the radius used by binary close. Defaults to 2.
- Returns:
Lung mask
- Return type:
sitk.Image
platipy.imaging.utils.valve module#
- platipy.imaging.utils.valve.generate_valve_from_great_vessel(label_great_vessel, label_ventricle, valve_thickness_mm=8)#
Generates a geometrically-defined valve. This function is suitable for the pulmonic and aortic valves.
- Parameters:
label_great_vessel (SimpleITK.Image) – The binary mask for the great vessel (pulmonary artery or ascending aorta)
label_ventricle (SimpleITK.Image) – The binary mask for the ventricle (left or right)
valve_thickness_mm (int, optional) – Valve thickness, in millimetres. Defaults to 8.
- Returns:
The geometric valve, as a binary mask.
- Return type:
SimpleITK.Image
- platipy.imaging.utils.valve.generate_valve_using_cylinder(label_atrium, label_ventricle, radius_mm=15, height_mm=10)#
Generates a geometrically-defined valve. This function is suitable for the tricuspid and mitral valves.
- Parameters:
label_atrium (SimpleITK.Image) – The binary mask for the (left or right) atrium.
label_ventricle (SimpleITK.Image) – The binary mask for the (left or right) ventricle.
radius_mm (int, optional) – The valve radius, in mm. Defaults to 15.
height_mm (int, optional) – The valve height (i.e. perpendicular extent), in mm. Defaults to 10.
- Returns:
The geometrically defined valve
- Return type:
SimpleITK.Image
platipy.imaging.utils.vessel module#
- platipy.imaging.utils.vessel.com_from_image_list(sitk_image_list, condition_type='count', condition_value=0, scan_direction='z')#
- Input: list of SimpleITK images
minimum total slice area required for the tube to be inserted at that slice scan direction: x = sagittal, y=coronal, z=axial
Output: mean centre of mass positions, with shape (NumSlices, 2) Note: positions are converted into image space by default
- platipy.imaging.utils.vessel.convert_simpleitk_to_vtk(img)#
Converts from SimpleITK to VTK representation
- Parameters:
img (SimpleITK.Image) – The input image.
- Returns:
The VTK image.
- platipy.imaging.utils.vessel.simpleitk_image_from_vtk_tube(tube, sitk_reference_image)#
Input: VTK tube, referenceImage (used for spacing, etc.) Output: SimpleITK image Note: Uses binary output (background 0, foreground 1)
- platipy.imaging.utils.vessel.tube_from_com_list(com_list, radius)#
Input: image-space positions along the tube centreline. Output: VTK tube Note: positions do not have to be continuous - the tube is interpolated in real space
- platipy.imaging.utils.vessel.vessel_spline_generation(reference_image, atlas_set, vessel_name_list, vessel_radius_mm_dict, stop_condition_type_dict, stop_condition_value_dict, scan_direction_dict, atlas_label='DIR')#
Generates a splined vessel from a list of binary masks.
- Parameters:
reference_image (SimpleITK.Image) – The reference image to copy information from.
atlas_set (dict) –
A dictionary conforming to the following format: { atlas_id:
- {
- LABEL:
- {
structure_a: SimpleITK.Image, structure_b: SimpleITK.Image, structure_c: SimpleITK.Image, …
}
} where LABEL should be passed as the atlas_label argument, and atlas_id is some label for each atlas.
vessel_name_list (list) – The list of vessels to generate splines for.
vessel_radius_mm_dict (list) – A dictionary specifying the radius for each vessel.
stop_condition_type_dict (dict) – A dictionary specifying the stopping condition for each vessel. Available options are “count” - stopping at a particular number of atlases, or “area” - stopping at a particular total area (in square pixels). Recommendation is to use “count” with a stop_condition_value (see below) of ~1/3 the number of atlases.
stop_condition_value_dict (dict) – A dictionary specifying the stopping value for each vessel.
scan_direction_dict (dict) – A dictionary specifying the direction to spline each vessel. “x”: sagittal, “y”: coronal, “z”: axial.
atlas_label (str, optional) – The atlas label. Defaults to “DIR”.
- Returns:
- The output dictionary, with keys as the vessel names and values as the binary labels
defining the splined vessels
- Return type:
dict
- platipy.imaging.utils.vessel.write_vtk_tube_to_file(tube, filename)#
Input: VTK tube Output: exit success Note: format is XML VTP