CorpusCallosum.utils.mapping_helpers¶
- CorpusCallosum.utils.mapping_helpers.apply_transform_to_pt(pts, T, inv=False)[source]¶
Apply homogeneous transformation matrix to points.
- Parameters:
- pts
np.ndarray Point coordinates to transform, shape (3,) or (3, N).
- T
np.ndarray 4x4 homogeneous transformation matrix.
- inv
bool, default=False If True, applies inverse of transformation.
- pts
- Returns:
np.ndarrayTransformed point coordinates, shape (3,) or (3, N).
- CorpusCallosum.utils.mapping_helpers.apply_transform_to_volume(orig_image, interp_vox2vox, save_vox2ras=None, header=None, output_path=None, output_size=None, order=1)[source]¶
Apply transformation to a volume and save the result.
- Parameters:
- orig_image
nibabelImage Input volume.
- interp_vox2vox
np.ndarray Transformation matrix to apply to the data, this is from input-to-output space.
- save_vox2ras
AffineMatrix4x4,optional The vox2ras matrix of the output image, only relevant if output_path is given.
- header
nibabelHeader,optional Header for the output image, only relevant if output_path is given, if None will default to orig_image header.
- output_path
strorPath,optional If output_path is provided, saves the result under this path using the dtype of header (or orig_image).
- output_size
np.ndarray,optional Size of output volume, uses input size by default
None.- order
int, default=1 Order of interpolation.
- orig_image
- Returns:
np.ndarrayTransformed volume data of shape
output_sizeand type float.
Notes
Uses
scipy.ndimage.affine_transformfor the transformation, and inverts vox2vox internally as required byaffine_transform.
- CorpusCallosum.utils.mapping_helpers.calc_mapping_to_standard_space(orig, ac_coords_3d, pc_coords_3d, orig_fsaverage_vox2vox)[source]¶
Get transformations to map image to standard space.
- Parameters:
- orig
nibabelImage Original image.
- ac_coords_3d
np.ndarray AC coordinates in 3D space.
- pc_coords_3d
np.ndarray PC coordinates in 3D space.
- orig_fsaverage_vox2vox
AffineMatrix4x4 Transformation matrix from original to fsaverage space.
- orig
- Returns:
- standardized_to_orig_vox2vox
AffineMatrix4x4 The vox2vox transformation matrix from standard space to original space.
- ac_coords_standardized
Vector3d AC coordinates in standard space.
- pc_coords_standardized
Vector3d PC coordinates in standard space.
- ac_coords_orig
Vector3d AC coordinates in original space.
- pc_coords_orig
Vector3d PC coordinates in original space.
- standardized_to_orig_vox2vox
- CorpusCallosum.utils.mapping_helpers.correct_nodding(ac_pt, pc_pt)[source]¶
Calculate rotation matrix to correct head nodding.
Calculates rotation matrix to align AC-PC line with posterior direction, correcting for head nodding based on AC-PC line orientation.
- Parameters:
- ac_pt
Vector2d 2D coordinates of the anterior commissure point.
- pc_pt
Vector2d 2D coordinates of the posterior commissure point.
- ac_pt
- Returns:
RotationMatrix3x3 rotation matrix to align AC-PC line with posterior direction.
- CorpusCallosum.utils.mapping_helpers.make_affine(simpleITKImage)[source]¶
Create an affine transformation matrix from a SimpleITK image.
- Parameters:
- simpleITKImage
sitk.Image Input SimpleITK image.
- simpleITKImage
- Returns:
np.ndarray4x4 affine transformation matrix in RAS coordinates.
Notes
The function: 1. Gets affine transform in LPS coordinates 2. Converts to RAS coordinates to match nibabel 3. Returns the final 4x4 transformation matrix
- CorpusCallosum.utils.mapping_helpers.make_midplane_affine(orig_affine, slices_to_analyze=1, offset=4)[source]¶
Create affine transformation matrix for midplane slices.
- CorpusCallosum.utils.mapping_helpers.map_softlabels_to_orig(cc_fn_softlabels, orig, orig2slab_vox2vox, cc_subseg_midslice=None, orig2midslice_vox2vox=None, orig_space_segmentation_path=None)[source]¶
Map soft labels back to original image space and apply post-processing.
- Parameters:
- cc_fn_softlabels
np.ndarray Soft label predictions of shape (H, W, D, C=3).
- orig
nibabelImage Original image.
- orig2slab_vox2vox
AffineMatrix4x4 The vox2vox transformation matrix from orig to the slab.
- cc_subseg_midslice
np.ndarray,optional Mask for subdividing regions of shape (H, D) (only paired with orig2midslice_vox2vox).
- orig2midslice_vox2vox
AffineMatrix4x4,optional The vox2vox transformation matrix from orig to the midslice (only paired with cc_subseg_midslice).
- orig_space_segmentation_path
strorPath,optional Path to save segmentation in original space.
- cc_fn_softlabels
- Returns:
np.ndarrayFinal segmentation in original image space.
Notes
The function: 1. Transforms background, cc, and fornix label channels separately. 2. Transform CC subsegmentation from midslice to orig and paint into segmentation if
cc_subseg_midsliceis passed. 4. Saves result toorig_space_segmentation_pathif passed.