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, subdivision_lines, 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).
- subdivision_lines
list[np.ndarray] List of pairs of points defining the subdivision lines.
- 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. Creates coordinate grids for all points in the slice. 2. Initializes mask with first segment label. 3. 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.
- 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, orig_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).
- orig_header
nibabelHeader Header of the conformed orig image. Surface files intended for inspection with orig.mgz must be written with this geometry metadata.
- 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.
intNumber of failed slices.
- CorpusCallosum.shape.postprocessing.subdivide_contour(midline_equi, subdivisions, ac_pt_acpc, contour_in_acpc_space, subdivision_method)[source]¶
Subdivide the contour based on the subdivision method.
- Parameters:
- midline_equi
Points2dType The midline equidistant points in ACPC space.
- subdivisions
list[float] The subdivisions.
- ac_pt_acpc
Vector2d The AC point in ACPC space (needed for eigenvector subdivision).
- contour_in_acpc_space
Points2dType The contour in ACPC space.
- subdivision_method
SubdivisionMethod The subdivision method. One of “shape”, “vertical”, “angular”, or “eigenvector”.
- midline_equi
- Returns:
tuple[list[float],ContourList,np.ndarray,list[Points2dType]]The areas, split contours, split points midline, and subdivision lines.
- CorpusCallosum.shape.postprocessing.test_left_of_line(coords, line_start, line_end)[source]¶
Test whether points in coords are to the left 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].
- CorpusCallosum.shape.postprocessing.test_posterior_of_line(coords_as, line_start, line_end)[source]¶
Test whether points in AS coordinates are posterior to a subdivision line.
Subdivision lines are stored as the two intersections with the contour. The order of those intersections depends on contour traversal and is not an anatomical direction. Determine which side is anterior by testing a point one millimeter anterior to the line midpoint, then return the opposite side.