@@ -35,9 +35,17 @@ def __init__(self, subject_code : str, work_path : str):
35
35
@type work_path: str
36
36
37
37
'''
38
- self .allowed_image_types = ["CT" , "T1w" , "T2w" , "FLAIR" , "DWI" , "BOLD" ]
38
+
39
+ # List of allowed image types
40
+ # CT: postop CT
41
+ # T1w: preop T1w MRI without contrast
42
+ # T2w: preop T2w MRI
43
+ # FLAIR: preop FLAIR MRI
44
+ # preopCT: preop CT (for showing blood vessels)
45
+ # T1wContrast: preop T1w MRI with contrast (for showing blood vessels)
46
+ # fGATIR: preop fast Gray Matter Acquisition T1 Inversion Recovery
47
+ self .allowed_image_types = ["CT" , "T1w" , "T2w" , "FLAIR" , "preopCT" , "T1wContrast" , "fGATIR" ]
39
48
# Each item is a dictionary returned by `parse_bids_filename`
40
- # Keys are image types (e.g., `CT`, `T1w`, `T2w`, `FLAIR`, `DWI`, `BOLD`)
41
49
self ._images = {}
42
50
43
51
self ._subject_code = subject_code
@@ -89,7 +97,7 @@ def input_image_path(self, type : str, relative : bool = False):
89
97
'''
90
98
Get the path to the image.
91
99
92
- @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI ", "BOLD ")
100
+ @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
93
101
@type type: str
94
102
95
103
@param relative: If True, return the relative path (to the working directory).
@@ -141,7 +149,7 @@ def expected_image_path(self, type : str, folder : str = None, name = None, **kw
141
149
'''
142
150
Get the expected path to the image.
143
151
144
- @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI ", "BOLD ")
152
+ @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
145
153
@type type: str
146
154
147
155
@param folder: The folder where the image is expected to be found.
@@ -171,7 +179,7 @@ def set_image(self, type : str, path : str, **kwargs):
171
179
'''
172
180
Set the path to the image.
173
181
174
- @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI ", "BOLD ")
182
+ @param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
175
183
@type type: str
176
184
177
185
@param path: The path to the image.
@@ -192,10 +200,12 @@ def set_image(self, type : str, path : str, **kwargs):
192
200
raise FileExistsError (f"Image type { type } already exists. If you want to overwrite it, set `overwrite=True`." )
193
201
try :
194
202
parsed = parse_bids_filename (os .path .basename (path ))
195
- parsed ['folder' ] = "inputs/anat"
196
- parsed = self ._fix_image_path (parsed )
197
203
if parsed is None :
198
204
raise ValueError ("Invalid BIDS filename" )
205
+ parsed ['folder' ] = "inputs/anat"
206
+ parsed ['type' ] = type
207
+ parsed ['ext' ] = "nii.gz"
208
+ parsed = self ._fix_image_path (parsed )
199
209
except :
200
210
parsed = self ._fix_image_path ({
201
211
'folder' : "inputs/anat" ,
@@ -228,18 +238,22 @@ def input_flair_path(self):
228
238
return self .input_image_path ("FLAIR" )
229
239
230
240
@property
231
- def input_dwi_path (self ):
232
- return self .input_image_path ("DWI" )
241
+ def input_preopCT_path (self ):
242
+ return self .input_image_path ("preopCT" )
243
+
244
+ @property
245
+ def input_fGATIR_path (self ):
246
+ return self .input_image_path ("fGATIR" )
233
247
234
248
@property
235
- def input_bold_path (self ):
236
- return self .input_image_path ("BOLD " )
249
+ def input_t1wcontrast_path (self ):
250
+ return self .input_image_path ("T1wContrast " )
237
251
238
252
def register_to_T1w (self , type : str , reverse : bool = False , verbose : bool = True ):
239
253
'''
240
254
Register an image to the T1w image.
241
255
242
- @param type: The type of the image (e.g., `CT`, `T2w`, "FLAIR", "DWI ", "BOLD ")
256
+ @param type: The type of the image (e.g., `CT`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
243
257
@type type: str
244
258
245
259
@param reverse: If True, register the T1w image to the image (switch the fixed and moving images).
@@ -307,17 +321,17 @@ def register_to_T1w(self, type : str, reverse : bool= False, verbose : bool=True
307
321
ct_img .set_qform (new_sform )
308
322
ct_img .to_filename ( ensure_basename ( self .expected_image_path ( type , "coregistration/anat" , space = "scanner" ) ) )
309
323
# save the mapping configurations
310
- mappings = self .get_native_mappings (type , relative = True )
324
+ mappings = self .get_native_mapping (type , relative = True )
311
325
log_file = ensure_basename ( self .format_path (folder = "coregistration/log" , name = "mapping" , ext = "json" , space = "scanner" , orig = type ) )
312
326
with open (log_file , "w" ) as f :
313
327
json .dump (mappings , f )
314
328
return mappings
315
329
316
- def get_native_mappings (self , type : str = "CT" , relative : bool = False ):
330
+ def get_native_mapping (self , type : str = "CT" , relative : bool = False ):
317
331
'''
318
332
Get the mappings for the native image.
319
333
320
- @param type: The type of the image modality (e.g., "CT", "T2w", "FLAIR", "DWI ", "BOLD ")
334
+ @param type: The type of the image modality (e.g., "CT", "T2w", "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
321
335
@type type: str
322
336
323
337
@param relative: If True, return the relative path (to the working directory).
@@ -344,6 +358,8 @@ def get_native_mappings(self, type : str = "CT", relative : bool = False):
344
358
'mappings' : {},
345
359
}
346
360
mappings = result ['mappings' ]
361
+ if not os .path .exists (tranform_rootdir ):
362
+ ensure_dir (tranform_rootdir )
347
363
for filename in os .listdir ( tranform_rootdir ):
348
364
if os .path .isfile ( file_path (tranform_rootdir , filename ) ):
349
365
try :
@@ -353,6 +369,8 @@ def get_native_mappings(self, type : str = "CT", relative : bool = False):
353
369
mappings [parsed ['type' ]] = file_path (transform_prefix , filename )
354
370
except :
355
371
continue
372
+ if not os .path .exists (aligned_rootdir ):
373
+ ensure_dir (aligned_rootdir )
356
374
for filename in os .listdir ( aligned_rootdir ):
357
375
if os .path .isfile ( file_path (aligned_rootdir , filename ) ):
358
376
try :
@@ -378,7 +396,7 @@ def map_to_template(self,
378
396
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
379
397
@type template_name: str
380
398
381
- @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI ", "BOLD ")
399
+ @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR ")
382
400
@type native_type: str
383
401
384
402
@param reverse: If True, register the template image to the image (switch the fixed and moving images).
@@ -503,7 +521,7 @@ def get_template_mapping(self, template_name : str, native_type : str = "T1w", r
503
521
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
504
522
@type template_name: str
505
523
506
- @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI ", "BOLD "), default is `T1w`.
524
+ @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR "), default is `T1w`.
507
525
@type native_type: str
508
526
509
527
@param relative: If True, return the relative path (to the working directory).
@@ -515,6 +533,8 @@ def get_template_mapping(self, template_name : str, native_type : str = "T1w", r
515
533
if native_type not in self .allowed_image_types :
516
534
raise ValueError (f"Invalid image type: { native_type } . Must be one of { self .allowed_image_types } " )
517
535
tranform_rootdir = file_path (self ._work_path , "normalization/transformations" )
536
+ if not os .path .exists (tranform_rootdir ):
537
+ return None
518
538
forward_list = []
519
539
inverse_list = []
520
540
for filename in os .listdir ( tranform_rootdir ):
@@ -564,7 +584,7 @@ def transform_image_from_template(self, path : str, template_name : str, native_
564
584
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
565
585
@type template_name: str
566
586
567
- @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI ", "BOLD "), default is `T1w`.
587
+ @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR "), default is `T1w`.
568
588
@type native_type: str
569
589
570
590
@return: The mapped image.
@@ -595,7 +615,7 @@ def transform_points_to_template(self, points : np.ndarray, template_name : str,
595
615
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
596
616
@type template_name: str
597
617
598
- @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI ", "BOLD "), default is `T1w`.
618
+ @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR "), default is `T1w`.
599
619
@type native_type: str
600
620
601
621
@return: The mapped points.
@@ -643,7 +663,7 @@ def transform_points_from_template(self, points : np.ndarray, template_name : st
643
663
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
644
664
@type template_name: str
645
665
646
- @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI ", "BOLD "), default is `T1w`.
666
+ @param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT ", "T1wContrast", "fGATIR "), default is `T1w`.
647
667
@type native_type: str
648
668
649
669
@return: The mapped points.
0 commit comments