@@ -299,6 +299,104 @@ def nonlateral_aseg_recoder(include_lesions=False):
299299
300300 return LabelRecoder (mapping , target = target_lut )
301301
302+ def lateral_aseg_recoder (include_lesions = False ):
303+ """
304+ Returns a recoding table that converts default brain labels to the
305+ corresponding tissue-type.
306+
307+ Returns:
308+ RecodingLookupTable: .
309+ """
310+ include_list = [
311+ "Unknown" ,
312+ "Left-Cerebral-White-Matter" ,
313+ "Right-Cerebral-White-Matter" ,
314+ "Left-Cerebral-Cortex" ,
315+ "Right-Cerebral-Cortex" ,
316+ "Left-Cerebellum-White-Matter" ,
317+ "Right-Cerebellum-White-Matter" ,
318+ "Left-Cerebellum-Cortex" ,
319+ "Right-Cerebellum-Cortex" ,
320+ "Left-Thalamus" ,
321+ "Right-Thalamus" ,
322+ "Left-Caudate" ,
323+ "Right-Caudate" ,
324+ "Left-Putamen" ,
325+ "Right-Putamen" ,
326+ "Left-Pallidum" ,
327+ "Right-Pallidum" ,
328+ "3rd-Ventricle" ,
329+ "4th-Ventricle" ,
330+ "Brain-Stem" ,
331+ "Left-Hippocampus" ,
332+ "Right-Hippocampus" ,
333+ "Left-Amygdala" ,
334+ "Right-Amygdala" ,
335+ "CSF" ,
336+ "Left-Lesion" ,
337+ "Right-Lesion" ,
338+ "Left-Accumbens-area" ,
339+ "Right-Accumbens-area" ,
340+ "Left-VentralDC" ,
341+ "Right-VentralDC" ,
342+ "Left-Choroid-Plexus"
343+ "Right-Choroid-Plexus"
344+ ]
345+ aseg = labels ()
346+ source_lut = labels ()
347+ target_lut = LabelLookup ()
348+ mapping = {}
349+ for key in source_lut .keys ():
350+ l_name = source_lut [key ].name
351+ if (key >= 1000 and key < 3000 ) or \
352+ (key > 11000 and key < 13000 ): # destrieux labels
353+ if is_r_label (l_name ):
354+ name = 'Right-Cerebral-Cortex'
355+ else :
356+ name = 'Left-Cerebral-Cortex'
357+ elif (key >= 3000 and key < 5000 ) or (key >= 13000 and key < 15000 ) or (key >= 250 and key <= 255 ):
358+ if is_r_label (l_name ):
359+ name = 'Right-Cerebral-White-Matter'
360+ else :
361+ name = 'Left-Cerebral-White-Matter'
362+ elif (key >= 7000 and key <= 7020 ):
363+ if is_r_label (l_name ):
364+ name = 'Right-Amygdala'
365+ else :
366+ name = 'Left-Amygdala'
367+ elif (key >= 8000 and key < 9000 ):
368+ if is_r_label (l_name ):
369+ name = 'Right-Thalamus'
370+ else :
371+ name = 'Left-Thalamus'
372+ elif key < 100 :
373+ name = l_name
374+ if (name .find ('Vent' ) >= 0 and name .find ('entral' ) < 0 ):
375+ name = 'CSF'
376+ if name .find ('ypoint' ) >= 0 or name .find ('esion' ) >= 0 or \
377+ name .find ('wmsa' ) >= 0 :
378+ if is_r_label (name ):
379+ name = 'Right-Lesion'
380+ else :
381+ name = 'Left-Lesion'
382+ else :
383+ continue
384+
385+ if name not in include_list :
386+ continue
387+
388+ source_key = key
389+ target_list = target_lut .search (name )
390+
391+ if len (target_list ) == 0 : # not already
392+ target_key = len (target_lut )
393+ target_lut [target_key ] = (name , source_lut [key ].color )
394+ else :
395+ target_key = target_list [0 ]
396+
397+ mapping [source_key ] = target_key
398+
399+ return LabelRecoder (mapping , target = target_lut )
302400
303401def tissue_type_recoder (extra = False , lesions = False ):
304402 """
@@ -875,3 +973,19 @@ def tissue_type_reduced24_recoder():
875973 }
876974
877975 return LabelRecoder (mapping , target = tissue_types ())
976+
977+ def is_r_label (label_name ):
978+ """
979+ Returns an int corresponding to the 'sidedness' of a label name
980+
981+ Returns
982+ -------
983+ int : 1 if name corresponds to right hemi; 0 if the name corresponds to
984+ the left hemi; -1 if there is no left/right associated with the label
985+ """
986+ if '-rh-' in label_name or '_rh_' in label_name or 'Right-' in label_name :
987+ return 1
988+ elif '-lh-' in label_name or '_lh_' in label_name or 'Left-' in label_name :
989+ return 0
990+ else :
991+ return - 1
0 commit comments