Skip to content

Commit 3050a54

Browse files
committed
fix: apply recenter only within the mask
FSL PRELUDE will return some values unwrapped below zero, making it hard to differenciate these pixels from the mask. This commit addresses that particular issue.
1 parent 79e5871 commit 3050a54

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sdcflows/workflows/phdiff.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def init_phdiff_wf(omp_nthreads, name='phdiff_wf'):
141141
(inputnode, phmap2rads, [('phasediff', 'in_file')]),
142142
(phmap2rads, prelude, [('out_file', 'phase_file')]),
143143
(prelude, recenter, [('unwrapped_phase_file', 'in_file')]),
144+
(bet, recenter, [('mask_file', 'in_mask')]),
144145
(recenter, denoise, [('out', 'in_file')]),
145146
(denoise, demean, [('out_file', 'in_file')]),
146147
(demean, cleanup_wf, [('out', 'inputnode.in_file')]),
@@ -154,9 +155,9 @@ def init_phdiff_wf(omp_nthreads, name='phdiff_wf'):
154155
return workflow
155156

156157

157-
def _recenter(in_file, offset=None):
158+
def _recenter(in_file, in_mask=None, offset=None):
158159
"""Recenter the phase-map distribution to the -pi..pi range."""
159-
from os.path import basename
160+
from os import getcwd
160161
import numpy as np
161162
import nibabel as nb
162163
from nipype.utils.filemanip import fname_presuffix
@@ -165,8 +166,15 @@ def _recenter(in_file, offset=None):
165166
offset = np.pi
166167

167168
nii = nb.load(in_file)
168-
data = nii.get_fdata(dtype='float32') - offset
169+
data = nii.get_fdata(dtype='float32')
169170

170-
out_file = fname_presuffix(basename(in_file), suffix='_recentered')
171+
msk = data > 1.e-6
172+
if in_mask is not None:
173+
msk = nb.load(in_mask).get_fdata(dtype='float32') > 1.e-4
174+
175+
data[msk] -= offset
176+
177+
out_file = fname_presuffix(in_file, suffix='_recentered',
178+
newpath=getcwd())
171179
nb.Nifti1Image(data, nii.affine, nii.header).to_filename(out_file)
172180
return out_file

0 commit comments

Comments
 (0)