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:
- header
nibabelHeader The header object used to initialize the generated header.
- header_dict
MGHHeaderDict A dictionary of values to overwrite in the generated header.
- header
- Returns:
MGHHeaderThe 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_data
np.ndarray Array of intensity data.
- aseg_nib
nibabelImage Subject’s segmentation image in native subject space.
- orig2midslice_vox2vox
np.ndarray Transformation matrix from subject/native space to fsaverage space (in lia).
- model_localization
DenseNet Trained model for AC-PC detection.
- resample_shape3-tuple
ofints Number of slices to process.
- orig_data
- Returns:
- ac_coords
np.ndarray AC voxel coordinates with shape (2,) containing its [y,x] positions.
- pc_coords
np.ndarray PC voxel coordinates with shape (2,) containing its [y,x] positions.
- ac_coords
- 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_name
strorPath Path to input MRI file.
- aseg_name
strorPath Path to input segmentation file.
- subject_dir
strorPath FastSurfer/FreeSurfer subject directory and directory for output files.
- slice_selection“middle”, “all” or
int, default=”middle” Which slices to process.
- num_thickness_points
int, default=100 Number of points for thickness estimation.
- subdivisions
list[float],optional List of subdivision fractions for CC subsegmentation.
- subdivision_method
anyof“shape”, “vertical”, “angular”, “eigenvector”, default=”shape” Method for contour subdivision.
- contour_smoothing
int, default=5 Gaussian sigma for smoothing during contour detection.
- save_template_dir
strorPath,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.
- device
str, default=”auto” Device to run inference on (‘auto’, ‘cpu’, ‘cuda’, or ‘cuda:X’).
- upright_volume
strorPath,optional Path to save upright volume.
- segmentation
strorPath,optional Path to save segmentation.
- cc_measures
strorPath,optional Path to save post-processing results.
- cc_mid_measures
strorPath,optional Path to save CC markers.
- upright_lta
strorPath,optional Path to save upright LTA transform.
- orient_volume_lta
strorPath,optional Path to save orientation transform.
- cc_surf
strorPath,optional Path to save surface file.
- cc_thickness_overlay
strorPath,optional Path to save overlay file.
- cc_html
strorPath,optional Path to save HTML visualization.
- cc_surf_vtk
strorPath,optional Path to save VTK file.
- segmentation_in_orig
strorPath,optional Path to save segmentation in original space.
- qc_image
strorPath,optional Path to save QC images.
- thickness_image
strorPath,optional Path to save thickness visualization.
- softlabels_cc
strorPath,optional Path to save CC soft labels.
- softlabels_fn
strorPath,optional Path to save fornix soft labels.
- softlabels_background
strorPath,optional Path to save background soft labels.
- conf_name
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_nib
nibabel.analyze.SpatialImage Subject’s segmentation image.
- aseg_nib
- Returns:
- aseg2fsaverage_vox2vox
AffineMatrix4x4 Transformation matrix from original to fsaverage voxel space.
- aseg2fsaverage_ras2ras
AffineMatrix4x4 Transformation matrix from original to fsaverage RAS space.
- fsaverage_hires_vox2ras
AffineMatrix4x4 High-resolution fsaverage affine matrix.
- fsaverage_header
MGHHeaderDict FSAverage header fields for LTA writing.
- aseg2fsaverage_vox2vox
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:
- midslices
np.ndarray Array of mid-sagittal slices in upright space and LIA-orientation.
- ac_coords
np.ndarray AC voxel coordinates with shape (2,) containing its [y,x] positions.
- pc_coords
np.ndarray PC voxel coordinates with shape (2,) containing its [y,x] positions.
- aseg_nib
nibabelImage Subject’s cc_seg_labels image.
- model_segmentation
torch.nn.Module Trained model for CC cc_seg_labels.
- midslices
- Returns:
- cc_seg_labels
np.ndarray Binary cc_seg_labels of the corpus callosum in upright space and LIA-orientation.
- cc_softlabels
np.ndarray Soft cc_seg_labels probabilities of shape in upright space and LIA-orientation (H, W, D, C=3).
- cc_seg_labels