Skip to content

Commit 302614a

Browse files
committed
WIP: CSF normalization
1 parent 9476035 commit 302614a

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

nibabies/cli/parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ def _str_none(val):
753753
default=16,
754754
help='Frame to start head motion estimation on BOLD.',
755755
)
756+
g_baby.add_argument(
757+
'--norm-csf',
758+
action='store_true',
759+
help='Replace low intensity voxels in CSF mask with average',
760+
)
756761
return parser
757762

758763

nibabies/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ class workflow(_Config):
578578
"""Run FreeSurfer ``recon-all`` with the ``-logitudinal`` flag."""
579579
medial_surface_nan = None
580580
"""Fill medial surface with :abbr:`NaNs (not-a-number)` when sampling."""
581+
norm_csf = False
582+
"""Replace low intensity voxels in CSF mask with average."""
581583
project_goodvoxels = False
582584
"""Exclude voxels with locally high coefficient of variation from sampling."""
583585
regressors_all_comps = None

nibabies/workflows/anatomical/fit.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ def init_infant_anat_fit_wf(
184184
name='anat_buffer',
185185
)
186186

187+
# Additional CSF normalization, if necessary
188+
anat_norm_buffer = pe.Node(
189+
niu.IdentityInterface(fields=['anat_preproc']),
190+
name='anat_norm_buffer',
191+
)
192+
187193
if reference_anat == 'T1w':
188194
LOGGER.info('ANAT: Using T1w as the reference anatomical')
189195
workflow.connect([
@@ -637,24 +643,6 @@ def init_infant_anat_fit_wf(
637643
(binarize_t2w, t2w_buffer, [('out_file', 't2w_mask')]),
638644
]) # fmt:skip
639645
else:
640-
# Check whether we can convert a previously computed T2w mask
641-
# or need to run the atlas based brain extraction
642-
643-
# if t1w_mask:
644-
# LOGGER.info('ANAT T1w mask will be transformed into T2w space')
645-
# transform_t1w_mask = pe.Node(
646-
# ApplyTransforms(interpolation='MultiLabel'),
647-
# name='transform_t1w_mask',
648-
# )
649-
650-
# workflow.connect([
651-
# (t1w_buffer, transform_t1w_mask, [('t1w_mask', 'input_image')]),
652-
# (coreg_buffer, transform_t1w_mask, [('t1w2t2w_xfm', 'transforms')]),
653-
# (transform_t1w_mask, apply_t2w_mask, [('output_image', 'in_mask')]),
654-
# (t2w_buffer, apply_t1w_mask, [('t2w_preproc', 'in_file')]),
655-
# # TODO: Unsure about this connection^
656-
# ]) # fmt:skip
657-
# else:
658646
LOGGER.info('ANAT Atlas-based brain mask will be calculated on the T2w')
659647
brain_extraction_wf = init_infant_brain_extraction_wf(
660648
omp_nthreads=omp_nthreads,

nibabies/workflows/anatomical/preproc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ def init_anat_preproc_wf(
6666
(final_clip, outputnode, [('out_file', 'anat_preproc')]),
6767
]) # fmt:skip
6868
return wf
69+
70+
71+
def init_anat_csf_norm_wf(name='anat_csf_norm_wf') -> LiterateWorkflow:
72+
"""Replace low intensity voxels within the CSF mask with the median value."""
73+
74+
workflow = LiterateWorkflow(name=name)
75+
inputnode = niu.IdentityInterface(fields=['anat_preproc', 'anat_dseg'], name='inputnode')
76+
outputnode = niu.IdentityInterface(fields=['anat_preproc'], name='outputnode')
77+
78+
applymask = pe.Node(ApplyMask(), name='applymask')
79+
80+
norm2median = pe.Node(niu.Function(function=_normalize_csf), name='norm2median')
81+
# 1. mask brain with CSF mask
82+
# fslmaths input.nii.gz -mas aseg_label-CSF_mask.nii.gz input_CSF.nii.gz
83+
# 2. get median intensity of nonzero voxels in mask
84+
# fslstats input_CSF.nii.gz -P 50
85+
# 3. normalize CSF-masked T2w to the median
86+
# fslmaths input_CSF.nii.gz -bin -mul <median intensity from (> median_CSF.nii.gz
87+
# 4. make the modified T2w, setting voxel intensity to be the max between the original T2w's,
88+
# and the normalized mask from (3)'s:
89+
# fslmaths input.nii.gz -max median_CSF.nii.gz input_floorCSF.nii.gz
90+
91+
return workflow
92+
93+
94+
def _normalize_csf(in_file): ...

0 commit comments

Comments
 (0)