Skip to content

Commit 7874bc7

Browse files
committed
new way to deoblique
1 parent 829d762 commit 7874bc7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

fmriprep/interfaces/images.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def _run_interface(self, runtime):
293293

294294
class ValidateImageInputSpec(BaseInterfaceInputSpec):
295295
in_file = File(exists=True, mandatory=True, desc='input image')
296+
deoblique = traits.Bool(False, usedefault=True)
296297

297298

298299
class ValidateImageOutputSpec(TraitedSpec):
@@ -342,6 +343,15 @@ class ValidateImage(SimpleInterface):
342343
output_spec = ValidateImageOutputSpec
343344

344345
def _run_interface(self, runtime):
346+
347+
def deoblique(img):
348+
import os
349+
import nibabel as nb
350+
import numpy as np
351+
affine = img.affine
352+
affine[:3, :3] = np.diag(np.diag(affine[:3, :3]))
353+
return nb.Nifti1Image(np.asanyarray(img.dataobj), affine, img.header)
354+
345355
img = nb.load(self.inputs.in_file)
346356
out_report = os.path.join(runtime.cwd, 'report.html')
347357

@@ -370,7 +380,13 @@ def _run_interface(self, runtime):
370380

371381
# Both match, qform valid (implicit with match), codes okay -> do nothing, empty report
372382
if matching_affines and qform_code > 0 and sform_code > 0:
373-
self._results['out_file'] = self.inputs.in_file
383+
if self.inputs.deoblique:
384+
out_fname = fname_presuffix(self.inputs.in_file, suffix='_valid', newpath=runtime.cwd)
385+
img = deoblique(img)
386+
img.to_filename(out_fname)
387+
self._results['out_file'] = out_fname
388+
else:
389+
self._results['out_file'] = self.inputs.in_file
374390
open(out_report, 'w').close()
375391
self._results['out_report'] = out_report
376392
return runtime
@@ -418,6 +434,9 @@ def _run_interface(self, runtime):
418434
</p>
419435
"""
420436
snippet = '<h3 class="elem-title">%s</h3>\n%s\n' % (warning_txt, description)
437+
438+
if self.inputs.deoblique:
439+
img = deoblique(img)
421440
# Store new file and report
422441
img.to_filename(out_fname)
423442
with open(out_report, 'w') as fobj:

fmriprep/workflows/bold/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ def init_bold_reference_wf(omp_nthreads, bold_file=None, name='bold_reference_wf
103103

104104
gen_ref = pe.Node(EstimateReferenceImage(), name="gen_ref",
105105
mem_gb=1) # OE: 128x128x128x50 * 64 / 8 ~ 900MB.
106-
deoblique = pe.Node(afni.Refit(deoblique=True), name='deoblique')
107106
# Re-run validation; no effect if no sbref; otherwise apply same validation to sbref as bold
108-
validate_ref = pe.Node(ValidateImage(), name='validate_ref', mem_gb=DEFAULT_MEMORY_MIN_GB)
107+
validate_ref = pe.Node(ValidateImage(deoblique=True), name='validate_ref', mem_gb=DEFAULT_MEMORY_MIN_GB)
109108
enhance_and_skullstrip_bold_wf = init_enhance_and_skullstrip_bold_wf(omp_nthreads=omp_nthreads)
110109

111110
workflow.connect([

0 commit comments

Comments
 (0)