CorpusCallosum.fastsurfer_cc

class CorpusCallosum.fastsurfer_cc.ArgumentDefaultsHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Help message formatter which adds default values to argument help.

Methods

format_help()

start_section(heading)

add_argument

add_arguments

add_text

add_usage

end_section

CorpusCallosum.fastsurfer_cc.init_mgh_header(header, header_dict)[source]

Generates a MGHHeader object from a header and a header dictionary.

Parameters:
headernibabelHeader

The header object used to initialize the generated header.

header_dictMGHHeaderDict

A dictionary of values to overwrite in the generated header.

Returns:
MGHHeader

The header updated with values in header_dict.

CorpusCallosum.fastsurfer_cc.localize_ac_pc(orig_data, aseg_nib, orig2midslice_vox2vox, model_localization, resample_shape)[source]

Localize anterior and posterior commissure points in the brain.

Uses a trained model to detect AC and PC points in mid-sagittal slices, using the third ventricle as an anatomical reference.

Parameters:
orig_datanp.ndarray

Array of intensity data.

aseg_nibnibabelImage

Subject’s segmentation image in native subject space.

orig2midslice_vox2voxnp.ndarray

Transformation matrix from subject/native space to fsaverage space (in lia).

model_localizationDenseNet

Trained model for AC-PC detection.

resample_shape3-tuple of ints

Number of slices to process.

Returns:
ac_coordsnp.ndarray

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

pc_coordsnp.ndarray

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

CorpusCallosum.fastsurfer_cc.main(conf_name, aseg_name, subject_dir, slice_selection='middle', num_thickness_points=100, subdivisions=None, subdivision_method='shape', contour_smoothing=5, save_template_dir=None, device='auto', upright_volume=None, segmentation=None, cc_measures=None, cc_mid_measures=None, upright_lta=None, orient_volume_lta=None, cc_surf=None, cc_thickness_overlay=None, cc_html=None, cc_surf_vtk=None, segmentation_in_orig=None, qc_image=None, thickness_image=None, softlabels_cc=None, softlabels_fn=None, softlabels_background=None)[source]

Main pipeline function for corpus callosum analysis.

This function performs the complete corpus callosum analysis pipeline including registration, landmark detection, segmentation, and morphometry analysis.

Parameters:
conf_namestr or Path

Path to input MRI file.

aseg_namestr or Path

Path to input segmentation file.

subject_dirstr or Path

FastSurfer/FreeSurfer subject directory and directory for output files.

slice_selection“middle”, “all” or int, default=”middle”

Which slices to process.

num_thickness_pointsint, default=100

Number of points for thickness estimation.

subdivisionslist[float], optional

List of subdivision fractions for CC subsegmentation.

subdivision_methodany of “shape”, “vertical”, “angular”, “eigenvector”, default=”shape”

Method for contour subdivision.

contour_smoothingint, default=5

Gaussian sigma for smoothing during contour detection.

save_template_dirstr or Path, optional

Directory path where to save contours.txt and thickness_values.txt files. These files can be used to visualize the CC shape and volume in 3D. Files are only saved, if a valid directory path is passed.

devicestr, default=”auto”

Device to run inference on (‘auto’, ‘cpu’, ‘cuda’, or ‘cuda:X’).

upright_volumestr or Path, optional

Path to save upright volume.

segmentationstr or Path, optional

Path to save segmentation.

cc_measuresstr or Path, optional

Path to save post-processing results.

cc_mid_measuresstr or Path, optional

Path to save CC markers.

upright_ltastr or Path, optional

Path to save upright LTA transform.

orient_volume_ltastr or Path, optional

Path to save orientation transform.

cc_surfstr or Path, optional

Path to save surface file.

cc_thickness_overlaystr or Path, optional

Path to save overlay file.

cc_htmlstr or Path, optional

Path to save HTML visualization.

cc_surf_vtkstr or Path, optional

Path to save VTK file.

segmentation_in_origstr or Path, optional

Path to save segmentation in original space.

qc_imagestr or Path, optional

Path to save QC images.

thickness_imagestr or Path, optional

Path to save thickness visualization.

softlabels_ccstr or Path, optional

Path to save CC soft labels.

softlabels_fnstr or Path, optional

Path to save fornix soft labels.

softlabels_backgroundstr or Path, optional

Path to save background soft labels.

Notes

The function saves multiple outputs to specified paths or default locations in output_dir: - cc_markers.json: Contains detected landmarks and measurements. - midplane_slices.mgz: Extracted midplane slices. - upright_volume.mgz: Volume aligned to standard orientation. - segmentation.mgz: Corpus callosum segmentation. - cc_postproc_results.json: Enhanced postprocessing results. - Various visualization plots and transformation matrices.

The pipeline consists of the following steps: 1. Initializes environment and loads models. 2. Registers input image to fsaverage space. 3. Detects AC and PC points. 4. Segments the corpus callosum. 5. Performs enhanced post-processing analysis. 6. Saves results and visualizations.

CorpusCallosum.fastsurfer_cc.make_parser()[source]

Create the argument parse object for the pipeline.

CorpusCallosum.fastsurfer_cc.options_parse()[source]

Parse command line arguments for the pipeline.

CorpusCallosum.fastsurfer_cc.register_centroids_to_fsavg(aseg_nib)[source]

Perform centroid-based registration between subject and fsaverage space.

Computes a rigid transformation between the subject’s segmentation and fsaverage space by aligning centroids of corresponding anatomical structures.

Parameters:
aseg_nibnibabel.analyze.SpatialImage

Subject’s segmentation image.

Returns:
aseg2fsaverage_vox2voxAffineMatrix4x4

Transformation matrix from original to fsaverage voxel space.

aseg2fsaverage_ras2rasAffineMatrix4x4

Transformation matrix from original to fsaverage RAS space.

fsaverage_hires_vox2rasAffineMatrix4x4

High-resolution fsaverage affine matrix.

fsaverage_headerMGHHeaderDict

FSAverage header fields for LTA writing.

Notes

The function uses pre-computed fsaverage centroids and data from static files to perform the registration. It matches corresponding anatomical structures between the subject’s segmentation and fsaverage space.

CorpusCallosum.fastsurfer_cc.save_cc_measures_json(cc_mid_measure_file, metrics)[source]

Save JSON metrics file.

CorpusCallosum.fastsurfer_cc.segment_cc(midslices, ac_coords, pc_coords, aseg_nib, model_segmentation)[source]

Segment the corpus callosum using a trained model.

Performs corpus callosum segmentation on mid-sagittal slices using a trained model, with AC-PC points as anatomical references. Includes post-processing to clean the cc_seg_labels.

Parameters:
midslicesnp.ndarray

Array of mid-sagittal slices in upright space and LIA-orientation.

ac_coordsnp.ndarray

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

pc_coordsnp.ndarray

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

aseg_nibnibabelImage

Subject’s cc_seg_labels image.

model_segmentationtorch.nn.Module

Trained model for CC cc_seg_labels.

Returns:
cc_seg_labelsnp.ndarray

Binary cc_seg_labels of the corpus callosum in upright space and LIA-orientation.

cc_softlabelsnp.ndarray

Soft cc_seg_labels probabilities of shape in upright space and LIA-orientation (H, W, D, C=3).