platipy.imaging.generation package#
Submodules#
platipy.imaging.generation.augment module#
- class platipy.imaging.generation.augment.ContractAugment(mask, vector_contract=(10, 10, 10), gaussian_smooth=5, bone_mask=False)#
Bases:
DeformableAugment
- augment()#
- class platipy.imaging.generation.augment.ExpandAugment(mask, vector_expand=(10, 10, 10), gaussian_smooth=5, bone_mask=False)#
Bases:
DeformableAugment
- augment()#
- class platipy.imaging.generation.augment.ShiftAugment(mask, vector_shift=(10, 10, 10), gaussian_smooth=5)#
Bases:
DeformableAugment
- augment()#
- platipy.imaging.generation.augment.apply_augmentation(image, augmentation, masks=[])#
- platipy.imaging.generation.augment.generate_random_augmentation(ct_image, masks)#
platipy.imaging.generation.dvf module#
- platipy.imaging.generation.dvf.generate_field_asymmetric_contract(mask_image, vector_asymmetric_contract=(10, 10, 10), gaussian_smooth=5, compute_real_dvf=False)#
Contracts a structure (defined using a binary mask) using a specified vector.
- Parameters:
mask_image ([SimpleITK.Image]) – The binary mask to contract.
vector_asymmetric_contract (tuple, optional) – The contraction vector applied to the entire binary mask. Convention: (+/-, +/-, +/-) = (sup/inf, post/ant, left/right) border is contracted. Defined in millimetres. Defaults to (10, 10, 10).
gaussian_smooth (int | list, optional) – Scale of a Gaussian kernel used to smooth the deformation vector field. Defaults to 5.
compute_real_dvf (bool, optional) – If True, the real deformation vector field is computed. This involves a slower computation. Defaults to False.
- Returns:
The binary mask following the contract. [SimpleITK.DisplacementFieldTransform]: The transform representing the contract. [SimpleITK.Image]: The displacement vector field representing the contract.
- Return type:
[SimpleITK.Image]
- platipy.imaging.generation.dvf.generate_field_asymmetric_extend(mask_image, vector_asymmetric_extend=(10, 10, 10), gaussian_smooth=5)#
Extends a structure (defined using a binary mask) using a specified vector.
- Parameters:
mask_image ([SimpleITK.Image]) – The binary mask to extend.
vector_asymmetric_extend (tuple, optional) – The extension vector applied to the entire binary mask. Convention: (+/-, +/-, +/-) = (sup/inf, post/ant, left/right) border is extended. Defined in millimetres. Defaults to (10, 10, 10).
gaussian_smooth (int | list, optional) – Scale of a Gaussian kernel used to smooth the deformation vector field. Defaults to 5.
- Returns:
The binary mask following the extension. [SimpleITK.DisplacementFieldTransform]: The transform representing the extension. [SimpleITK.Image]: The displacement vector field representing the extension.
- Return type:
[SimpleITK.Image]
- platipy.imaging.generation.dvf.generate_field_expand(mask, bone_mask=False, expand=3, gaussian_smooth=5, use_internal_deformation=True)#
Expands a structure (defined using a binary mask) using a specified vector to define the dilation kernel.
- Parameters:
mask ([SimpleITK.Image]) – The binary mask to expand.
bone_mask ([SimpleITK.Image, optional]) – A binary mask defining regions where we expect restricted deformations.
vector_asymmetric_extend (int |tuple, optional) –
- The expansion vector applied to the entire
binary mask.
Convention: (z,y,x) size of expansion kernel. Defined in millimetres. Defaults to 3.
gaussian_smooth (int | list, optional) – Scale of a Gaussian kernel used to smooth the deformation vector field. Defaults to 5.
- Returns:
The binary mask following the expansion. [SimpleITK.DisplacementFieldTransform]: The transform representing the expansion. [SimpleITK.Image]: The displacement vector field representing the expansion.
- Return type:
[SimpleITK.Image]
- platipy.imaging.generation.dvf.generate_field_radial_bend(reference_image, body_mask, reference_point, axis_of_rotation=[0, 0, -1], scale=0.1, mask_bend_from_reference_point=('z', 'inf'), gaussian_smooth=5)#
Generates a synthetic field characterised by radial bending. Typically, this field would be used to simulate a moving head and so masking is important.
- Parameters:
reference_image ([SimpleITK.Image]) – The image to be deformed.
body_mask ([SimpleITK.Image]) – A binary mask in which the deformation field will be defined
reference_point ([tuple]) – The point (z,y,x) about which the rotation field is defined.
axis_of_rotation (tuple, optional) – The axis of rotation (z,y,x). Defaults to [0, 0, -1].
scale (int, optional) – The deformation vector length at each point will equal scale multiplied by the distance to that point from reference_point. Defaults to 1.
mask_bend_from_reference_point (tuple, optional) – The dimension (z=axial, y=coronal, x=sagittal) and limit (inf/sup, post/ant, left/right) for masking the vector field, relative to the reference point. Defaults to (“z”, “inf”).
gaussian_smooth (int | list, optional) – Scale of a Gaussian kernel used to smooth the deformation vector field. Defaults to 5.
- Returns:
The binary mask following the expansion. [SimpleITK.DisplacementFieldTransform]: The transform representing the expansion. [SimpleITK.Image]: The displacement vector field representing the expansion.
- Return type:
[SimpleITK.Image]
- platipy.imaging.generation.dvf.generate_field_shift(mask_image, vector_shift=(10, 10, 10), gaussian_smooth=5)#
Shifts (moves) a structure defined using a binary mask.
- Parameters:
mask_image ([SimpleITK.Image]) – The binary mask to shift.
vector_shift (tuple, optional) – The displacement vector applied to the entire binary mask. Convention: (+/-, +/-, +/-) = (sup/inf, post/ant, left/right) shift. Defined in millimetres. Defaults to (10, 10, 10).
gaussian_smooth (int | list, optional) – Scale of a Gaussian kernel used to smooth the deformation vector field. Defaults to 5.
- Returns:
The binary mask following the shift. [SimpleITK.DisplacementFieldTransform]: The transform representing the shift. [SimpleITK.Image]: The displacement vector field representing the shift.
- Return type:
[SimpleITK.Image]
platipy.imaging.generation.image module#
- platipy.imaging.generation.image.insert_cylinder(arr, cyl_radius=4, cyl_height=2, cyl_centre=(0, 0, 0))#
Insert a cylinder into the given array. The cylinder vertical extent is +/- 0.5 * height
- Parameters:
arr (np.ndarray) – The array into which the cylinder is inserted
cyl_radius (int, optional) – Cylinder radius. Defaults to 4.
cyl_height (int, optional) – Cylinder height. Defaults to 2.
cyl_centre (tuple, optional) – Cylinder centre. Defaults to (0, 0, 0).
- Returns:
The original array with a cylinder (value 1)
- Return type:
np.ndarray
- platipy.imaging.generation.image.insert_cylinder_image(image, cyl_radius=(5, 5), cyl_height=10, cyl_centre=(0, 0, 0))#
Insert a cylinder into an image
- Parameters:
image (SimpleITK.Image) –
cyl_radius (tuple, optional) – Cylinder radius, can be defined as a single value or a tuple (will generate an ellipsoid). Defaults to (5,5).
cyl_height (int, optional) – Cylinder height. Defaults to 10.
cyl_centre (tuple, optional) – Cylinder centre. Defaults to (0,0,0).
- Returns:
Image with cylinder inserted
- Return type:
SimpleITK.Image
- platipy.imaging.generation.image.insert_sphere(arr, sp_radius=4, sp_centre=(0, 0, 0))#
Insert a sphere into the given array
- Parameters:
arr (np.array) – Array in which to insert sphere
sp_radius (int, optional) – The radius of the sphere. Defaults to 4.
sp_centre (tuple, optional) – The position at which the sphere should be inserted. Defaults to (0, 0, 0).
- Returns:
An array with the sphere inserted
- Return type:
np.array
- platipy.imaging.generation.image.insert_sphere_image(image, sp_radius, sp_centre)#
Insert a sphere into an image
- Parameters:
image (sitk.Image) – Image in which to insert sphere
sp_radius (int | list, optional) – The radius of the sphere. Can also be defined as a vector. Defaults to 4.
sp_centre (tuple, optional) – The position at which the sphere should be inserted. Defaults to (0, 0, 0).
- Returns:
An array with the sphere inserted
- Return type:
np.array
platipy.imaging.generation.mask module#
- platipy.imaging.generation.mask.extend_mask(mask, direction=('ax', 'sup'), extension_mm=10, interior_mm_shape=10)#
Extends a binary label (mask) a number of slices. PROTOTYPE! Currently can only extend in axial directions (superior of inferior). The shape of the extended part is based on some number of interior slices, as defined.
- Parameters:
mask (SimpleITK.Image) – The input binary label (mask).
direction (tuple, optional) – The direction as a tuple. First element is axis, second element is direction. Defaults to (“ax”, “sup”).
extension_mm (int, optional) – The extension in millimeters. Defaults to 10.
interior_mm_shape (int, optional) – The length on which to base the extension shape. Defaults to 10.
- Returns:
The output (extended mask).
- Return type:
SimpleITK.Image
- platipy.imaging.generation.mask.get_bone_mask(image, lower_threshold=350, upper_threshold=3500, max_hole_size=5)#
Automatically generate a binary mask of bones from a CT image.
- Parameters:
image ([SimpleITK.Image]) – The patient x-ray CT image to segment.
lower_threshold (int, optional) – Lower voxel value for threshold. Defaults to 350.
upper_threshold (int, optional) – Upper voxel value for threshold. Defaults to 3500.
max_hole_size (int | list | bool, optional) – Maximum hole size to be filled in millimetres. Can be specified as a vector (z,y,x). Defaults to 5.
- Returns:
The binary bone mask.
- Return type:
[SimpleITK.Image]
- platipy.imaging.generation.mask.get_external_mask(image, lower_threshold=-100, upper_threshold=2500, dilate=1, max_hole_size=False)#
Automatically generate a binary mask of the patient external contour. Uses slice-wise convex hull generation.
- Parameters:
image ([SimpleITK.Image]) – The patient x-ray CT image to segment. May work with other modalities with modified thresholds.
lower_threshold (int, optional) – Lower voxel value for threshold. Defaults to -100.
upper_threshold (int, optional) – Upper voxel value for threshold. Defaults to 2500.
dilate (int | list | bool, optional) – Dilation filter size applied to the binary mask. Can be specified as a vector (z,y,x). Defaults to 1.
max_hole_size (int | list | bool, optional) – Maximum hole size to be filled in millimetres. Can be specified as a vector (z,y,x). Defaults to False.
- Returns:
The binary external mask.
- Return type:
[SimpleITK.Image]