CorpusCallosum.shape.postprocessing¶
- CorpusCallosum.shape.postprocessing.check_area_changes(contours, threshold=0.3)[source]¶
Check for large changes between consecutive CC areas and issue warnings.
- Parameters:
- contours
list[np.ndarray] List of contours (2, N).
- threshold
float, default=0.3 Threshold for relative change.
- contours
- Returns:
boolTrue if no large area changes are detected, False otherwise.
- CorpusCallosum.shape.postprocessing.make_subdivision_mask(slice_shape, split_contours, vox2ras, plot=False)[source]¶
Create a mask for subdividing the corpus callosum based on split contours.
- Parameters:
- slice_shape
pairofints Shape of the slice (rows, cols).
- split_contours
ContourList List of contours defining the subdivisions. Each contour is a tuple of x and y coordinates.
- vox2ras
AffineMatrix4x4 The vox2ras transformation matrix for the requested shape.
- plot
bool, default=False Whether to plot the subdivision mask.
- slice_shape
- Returns:
np.ndarrayA mask of shape slice_shape where each pixel is labeled with a value from SUBSEGEMNT_LABELS indicating which subdivision segment it belongs to.
Notes
The function: 1. Extracts unique contour points at subdivision boundaries. 2. Creates coordinate grids for all points in the slice. 3. Initializes mask with first segment label. 4. For each subdivision line: - Tests which points lie to the right of the line. - Updates labels for those points.
- CorpusCallosum.shape.postprocessing.offset_affine(offset)[source]¶
Generate an affine transformation matrix that only constitutes an offset (vector).
- Parameters:
- offsetarray_like
A 3-dimensional offset vector (shape (3,)) to offset with.
- Returns:
np.ndarrayModified 4x4 affine transformation matrix with the specific offset.
- Raises:
TypeErrorIf offset is not a
- CorpusCallosum.shape.postprocessing.recon_cc_surf_measure(segmentation, slice_idx, slice_lia_vox2midslice_ras, ac_coords_vox, pc_coords_vox, num_thickness_points, subdivisions, subdivision_method, contour_smoothing)[source]¶
Reconstruct surfaces and compute measures for a single slice for the corpus callosum.
- Parameters:
- segmentation
np.ndarray 3D segmentation array.
- slice_idx
int Index of the slice to process.
- slice_lia_vox2midslice_ras
AffineMatrix4x4 4x4 affine transformation matrix.
- ac_coords_vox
np.ndarray AC voxel coordinates with shape (2,) containing its [y,x] positions.
- pc_coords_vox
np.ndarray PC voxel coordinates with shape (2,) containing its [y,x] positions.
- num_thickness_points
int Number of points for thickness estimation.
- subdivisions
list[float] List of fractions for anatomical subdivisions.
- subdivision_method
SubdivisionMethod Method for contour subdivision (‘shape’, ‘vertical’, ‘angular’, or ‘eigenvector’).
- contour_smoothing
int Gaussian sigma for contour smoothing.
- segmentation
- Returns:
- measures
CCMeasuresDict Dictionary containing measurements if successful.
- contour
CCContour The contour object containing points, thickness values, and endpoint indices.
- measures
- Raises:
ValueErrorIf no CC is found in the specified slice.
Notes
The function performs the following steps: 1. Extracts CC contour and identifies endpoints. 2. Converts coordinates to RAS space. 3. Calculates thickness profile using Laplace equation. 4. Computes shape metrics and subdivisions. 5. Generates visualization data.
- CorpusCallosum.shape.postprocessing.recon_cc_surf_measures_multi(segmentation, slice_selection, upright_header, fsavg2midslab_vox2vox, fsavg_vox2ras, orig2fsavg_vox2vox, midslices, ac_coords_vox, pc_coords_vox, num_thickness_points, subdivisions, subdivision_method, contour_smoothing, subject_dir)[source]¶
Surface reconstruction and metrics computation of corpus callosum slices based on selection mode.
- Parameters:
- segmentation
np.ndarray 3D segmentation array in LIA orientation.
- slice_selection
str Which slices to process (‘middle’, ‘all’, or slice number).
- upright_header
MGHHeader The header of the upright image.
- fsavg2midslab_vox2vox
AffineMatrix4x4 The vox2vox transformation matrix from fsaverage (upright) space to the segmentation slab.
- fsavg_vox2ras
np.ndarray Base affine transformation matrix (fsaverage, upright space).
- orig2fsavg_vox2vox
AffineMatrix4x4 The transformation matrix from orig to fsaverage in voxel space.
- midslices
np.ndarray Array of mid-sagittal slices.
- ac_coords_vox
np.ndarray AC voxel coordinates with shape (2,) containing its [y,x] positions.
- pc_coords_vox
np.ndarray PC voxel coordinates with shape (2,) containing its [y,x] positions.
- num_thickness_points
int Number of points for thickness estimation.
- subdivisions
list[float] List of fractions for anatomical subdivisions.
- subdivision_method‘shape’, ‘vertical’, ‘angular’, ‘eigenvector’
Method for contour subdivision.
- contour_smoothing
int Gaussian sigma for contour smoothing.
- subject_dir
SubjectDirectory The SubjectDirectory object managing file names in the subject directory.
- segmentation
- Returns:
listofCCMeasuresDictList of slice processing results.
listofconcurrent.futures.FutureList of background IO processes.
listofCCContourList of CC contours.
CCMesh,NoneThe CC mesh or None if no mesh was created.
- CorpusCallosum.shape.postprocessing.test_right_of_line(coords, line_start, line_end)[source]¶
Test whether points in coords are to the right of the line (line_start->line_end).
- Parameters:
- coords
np.ndarray Array of coordinates of shape (…, N).
- line_startarray_like
[x, y] coordinates of line start point (N,).
- line_endarray_like
[x, y] coordinates of line end point (N,).
- coords
- Returns:
np.ndarrayBoolean array where True means point is to the left of the line of shape coords.shape[:-1].