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, split_contours, 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).

split_contoursContourList

List of contours defining the subdivisions. Each contour is a tuple of x and y coordinates.

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. 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.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 if successful.

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

3D segmentation array in LIA orientation.

slice_selectionstr

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

upright_headerMGHHeader

The header of the upright image.

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.

CCMesh, None

The 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:
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].