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:
contourslist[np.ndarray]

List of contours (2, N).

thresholdfloat, default=0.3

Threshold for relative change.

Returns:
bool

True 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_shapepair of ints

Shape of the slice (rows, cols).

subdivision_lineslist[np.ndarray]

List of pairs of points defining the subdivision lines.

vox2rasAffineMatrix4x4

The vox2ras transformation matrix for the requested shape.

plotbool, default=False

Whether to plot the subdivision mask.

Returns:
np.ndarray

A 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.ndarray

Modified 4x4 affine transformation matrix with the specific offset.

Raises:
TypeError

If 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:
segmentationnp.ndarray

3D segmentation array.

slice_idxint

Index of the slice to process.

slice_lia_vox2midslice_rasAffineMatrix4x4

4x4 affine transformation matrix.

ac_coords_voxnp.ndarray

AC voxel coordinates with shape (2,) containing its [y,x] positions.

pc_coords_voxnp.ndarray

PC voxel coordinates with shape (2,) containing its [y,x] positions.

num_thickness_pointsint

Number of points for thickness estimation.

subdivisionslist[float]

List of fractions for anatomical subdivisions.

subdivision_methodSubdivisionMethod

Method for contour subdivision (‘shape’, ‘vertical’, ‘angular’, or ‘eigenvector’).

contour_smoothingint

Gaussian sigma for contour smoothing.

Returns:
measuresCCMeasuresDict

Dictionary containing measurements.

contourCCContour

The contour object containing points, thickness values, and endpoint indices.

Raises:
ValueError

If 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:
segmentationnp.ndarray

3D segmentation array in LIA orientation.

slice_selectionstr

Which slices to process (‘middle’, ‘all’, or slice number).

orig_headernibabelHeader

Header of the conformed orig image. Surface files intended for inspection with orig.mgz must be written with this geometry metadata.

fsavg2midslab_vox2voxAffineMatrix4x4

The vox2vox transformation matrix from fsaverage (upright) space to the segmentation slab.

fsavg_vox2rasnp.ndarray

Base affine transformation matrix (fsaverage, upright space).

orig2fsavg_vox2voxAffineMatrix4x4

The transformation matrix from orig to fsaverage in voxel space.

midslicesnp.ndarray

Array of mid-sagittal slices.

ac_coords_voxnp.ndarray

AC voxel coordinates with shape (2,) containing its [y,x] positions.

pc_coords_voxnp.ndarray

PC voxel coordinates with shape (2,) containing its [y,x] positions.

num_thickness_pointsint

Number of points for thickness estimation.

subdivisionslist[float]

List of fractions for anatomical subdivisions.

subdivision_method‘shape’, ‘vertical’, ‘angular’, ‘eigenvector’

Method for contour subdivision.

contour_smoothingint

Gaussian sigma for contour smoothing.

subject_dirSubjectDirectory

The SubjectDirectory object managing file names in the subject directory.

Returns:
list of CCMeasuresDict

List of slice processing results.

list of concurrent.futures.Future

List of background IO processes.

list of CCContour

List of CC contours.

int

Number 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_equiPoints2dType

The midline equidistant points in ACPC space.

subdivisionslist[float]

The subdivisions.

ac_pt_acpcVector2d

The AC point in ACPC space (needed for eigenvector subdivision).

contour_in_acpc_spacePoints2dType

The contour in ACPC space.

subdivision_methodSubdivisionMethod

The subdivision method. One of “shape”, “vertical”, “angular”, or “eigenvector”.

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:
coordsnp.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,).

Returns:
np.ndarray

Boolean 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.