diff --git a/pyproject.toml b/pyproject.toml index bb8aea305f..b1d4bb0318 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ "matplotlib >= 3.5", "nibabel >= 4.0.1", "nipype >= 1.8.5", - "niworkflows >= 1.12.0", + "niworkflows >= 1.12.1", "numpy >= 1.24", "packaging >= 24", "pybids >= 0.16", diff --git a/src/smriprep/workflows/fit/registration.py b/src/smriprep/workflows/fit/registration.py index fc78575721..d75a12c894 100644 --- a/src/smriprep/workflows/fit/registration.py +++ b/src/smriprep/workflows/fit/registration.py @@ -38,9 +38,10 @@ def init_register_template_wf( *, - sloppy, - omp_nthreads, - templates, + sloppy: bool, + omp_nthreads: int, + templates: list[str], + image_type: str = 'T1w', name='register_template_wf', ): """ @@ -89,6 +90,8 @@ def init_register_template_wf( input domain to enable standardization of lesioned brains. template Template name and specification + image_type + Moving image modality Outputs ------- @@ -170,6 +173,15 @@ def init_register_template_wf( run_without_submitting=True, ) + set_reference = pe.Node( + niu.Function( + function=_set_reference, + output_names=['reference_type', 'use_histogram_matching'], + ), + name='set_reference', + ) + set_reference.inputs.image_type = image_type + # With the improvements from nipreps/niworkflows#342 this truncation is now necessary trunc_mov = pe.Node( ants.ImageMath(operation='TruncateImageIntensity', op2='0.01 0.999 256'), @@ -203,6 +215,14 @@ def init_register_template_wf( ('name', 'template'), ('spec', 'template_spec'), ]), + (tf_select, set_reference, [ + ('t1w_file', 'template_t1w'), + ('t2w_file', 'template_t2w'), + ]), + (set_reference, registration, [ + ('reference_type', 'reference'), + ('use_histogram_matching', 'use_histogram_matching'), + ]), (split_desc, registration, [ ('name', 'template'), ('spec', 'template_spec'), @@ -243,3 +263,27 @@ def _fmt_cohort(template, spec): if cohort is not None: template = f'{template}:cohort-{cohort}' return template, spec + + +def _set_reference(image_type, template_t1w, template_t2w=None): + """ + Determine the normalization reference and whether histogram matching will be used. + + Parameters + ---------- + image_type : MR image type of anatomical reference (T1w, T2w) + template_t1w : T1w file + template_t2w : T2w file or undefined + + Returns + ------- + reference_type : modality of template reference (T1w, T2w) + histogram_matching : False when image_type does not match reference image, otherwise Undefined + """ + from nipype.interfaces.base import Undefined + + if image_type == 'T2w': + if template_t2w: + return 'T2w', Undefined + return 'T1w', False + return 'T1w', Undefined