1414
1515import os
1616from pathlib import Path
17+ from typing import cast
1718
1819import nibabel as nib
1920import numpy as np
2223from CorpusCallosum .data import constants
2324from CorpusCallosum .shape .contour import CCContour
2425from CorpusCallosum .shape .postprocessing import recon_cc_surf_measure
26+ from FastSurferCNN .utils import nibabelImage
2527from FastSurferCNN .utils .brainvolstats import mask_in_array
2628
29+ FSAVERAGE_PC_COORDINATE = np .array ([131 , 99 ])
30+ FSAVERAGE_AC_COORDINATE = np .array ([135 , 130 ])
31+
2732
2833def smooth_contour (contour : tuple [np .ndarray , np .ndarray ], window_size : int = 5 ) -> tuple [np .ndarray , np .ndarray ]:
2934 """Smooth a contour using a moving average filter.
@@ -62,18 +67,16 @@ def smooth_contour(contour: tuple[np.ndarray, np.ndarray], window_size: int = 5)
6267 return (x_smoothed , y_smoothed )
6368
6469
65- def load_fsaverage_cc_template () -> tuple [
66- np .ndarray , tuple [np .ndarray , np .ndarray ], np .ndarray , np .ndarray , np .ndarray , tuple [int , int ]
67- ]:
70+ def load_fsaverage_cc_template () -> CCContour :
6871 """Load and process the fsaverage corpus callosum template.
6972
7073 This function loads the fsaverage segmentation from FreeSurfer's data directory,
7174 extracts the corpus callosum mask, and processes it to create a smooth template.
7275
7376 Returns
7477 -------
75- tuple
76- Contains :
78+ CCContour
79+ Object with all the contour information including :
7780 - contour : tuple[np.ndarray, np.ndarray] : x and y coordinates of the contour points.
7881 - anterior_endpoint_idx : np.ndarray : Index of the anterior endpoint.
7982 - posterior_endpoint_idx : np.ndarray : Index of the posterior endpoint.
@@ -95,13 +98,9 @@ def load_fsaverage_cc_template() -> tuple[
9598 f"FREESURFER_HOME environment variable" ) from err
9699
97100 fsaverage_seg_path = freesurfer_home / 'subjects' / 'fsaverage' / 'mri' / 'aparc+aseg.mgz'
98- fsaverage_seg = nib .load (fsaverage_seg_path )
101+ fsaverage_seg = cast ( nibabelImage , nib .load (fsaverage_seg_path ) )
99102 segmentation = np .asarray (fsaverage_seg .dataobj )
100103
101- PC = np .array ([131 , 99 ])
102- AC = np .array ([135 , 130 ])
103-
104-
105104 midslice = segmentation .shape [0 ]// 2 + 1
106105
107106 cc_mask = mask_in_array (segmentation [midslice ], constants .SUBSEGMENT_LABELS )
@@ -124,9 +123,9 @@ def load_fsaverage_cc_template() -> tuple[
124123 _ , contour_with_thickness , (anterior_endpoint_idx , posterior_endpoint_idx ) = recon_cc_surf_measure (
125124 segmentation = cc_mask [None ],
126125 slice_idx = 0 ,
127- ac_coords = AC ,
128- pc_coords = PC ,
129- affine = fsaverage_seg .affine ,
126+ ac_coords_vox = FSAVERAGE_AC_COORDINATE ,
127+ pc_coords_vox = FSAVERAGE_PC_COORDINATE ,
128+ slice_lia_vox2midslice_ras = fsaverage_seg .affine ,
130129 num_thickness_points = 100 ,
131130 subdivisions = [1 / 6 , 1 / 2 , 2 / 3 , 3 / 4 ],
132131 subdivision_method = "shape" ,
@@ -148,7 +147,7 @@ def load_fsaverage_cc_template() -> tuple[
148147 fsaverage_contour = CCContour (np .array (outside_contour ).T ,
149148 np .zeros (len (outside_contour [0 ])),
150149 endpoint_idxs = (anterior_endpoint_idx , posterior_endpoint_idx ),
151- resolution = 1 .0 )
150+ z_position = 0 .0 )
152151
153152
154153 return fsaverage_contour
0 commit comments