Skip to content

Commit 9039aaa

Browse files
committed
ENH: Increase threshold for PET brain mask
1 parent 1534270 commit 9039aaa

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

fmriprep/workflows/pet/confounds.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,28 @@ def _binary_union(mask1, mask2):
579579
return str(out_name)
580580

581581

582+
def _smooth_binarize(in_file, fwhm=10.0, thresh=0.2):
583+
"""Smooth ``in_file`` with a Gaussian kernel and binarize at ``thresh``."""
584+
from pathlib import Path
585+
586+
import nibabel as nb
587+
import numpy as np
588+
from scipy.ndimage import gaussian_filter
589+
590+
img = nb.load(in_file)
591+
data = img.get_fdata(dtype=np.float32)
592+
zooms = np.array(img.header.get_zooms()[:3], dtype=float)
593+
sigma = (fwhm / 2.3548) / zooms
594+
smoothed = gaussian_filter(data, sigma=sigma)
595+
mask = smoothed > (thresh * smoothed.max())
596+
597+
out_img = img.__class__(mask.astype('uint8'), img.affine, img.header)
598+
out_img.set_data_dtype('uint8')
599+
out_name = Path('smoothed_bin_mask.nii.gz').absolute()
600+
out_img.to_filename(out_name)
601+
return str(out_name)
602+
603+
582604
def _carpet_parcellation(segmentation, crown_mask, nifti=False):
583605
"""Generate a segmentation for carpet plot visualization."""
584606
from pathlib import Path

fmriprep/workflows/pet/fit.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,18 @@ def init_pet_fit_wf(
357357

358358
# Stage 4: Estimate PET brain mask
359359
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
360-
from niworkflows.interfaces.nibabel import Binarize
361360

362-
from .confounds import _binary_union
361+
from .confounds import _binary_union, _smooth_binarize
363362

364363
t1w_mask_tfm = pe.Node(
365364
ApplyTransforms(interpolation='MultiLabel', invert_transform_flags=[True]),
366365
name='t1w_mask_tfm',
367366
)
368-
petref_mask = pe.Node(Binarize(thresh_low=0.2), name='petref_mask')
367+
petref_mask = pe.Node(
368+
niu.Function(function=_smooth_binarize), name='petref_mask'
369+
)
370+
petref_mask.inputs.fwhm = 10.0
371+
petref_mask.inputs.thresh = 0.2
369372
merge_mask = pe.Node(niu.Function(function=_binary_union), name='merge_mask')
370373

371374
if not petref2anat_xform:
@@ -380,7 +383,7 @@ def init_pet_fit_wf(
380383
(inputnode, t1w_mask_tfm, [('t1w_mask', 'input_image')]),
381384
(petref_buffer, t1w_mask_tfm, [('petref', 'reference_image')]),
382385
(petref_buffer, petref_mask, [('petref', 'in_file')]),
383-
(petref_mask, merge_mask, [('out_mask', 'mask1')]),
386+
(petref_mask, merge_mask, [('out', 'mask1')]),
384387
(t1w_mask_tfm, merge_mask, [('output_image', 'mask2')]),
385388
(merge_mask, outputnode, [('out', 'pet_mask')]),
386389
]

0 commit comments

Comments
 (0)