From faad78fd01fa0029db4cb5b3a4971f9bbd193a79 Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Wed, 11 Dec 2024 15:17:54 -0500 Subject: [PATCH 1/4] ENH: Support spatial normalization to alternative modalities --- src/smriprep/workflows/fit/registration.py | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/smriprep/workflows/fit/registration.py b/src/smriprep/workflows/fit/registration.py index fc78575721..dfbefa1154 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): + """ + 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 From 19960650b0dca850accc4c5e3396042246d5a4cc Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Wed, 11 Dec 2024 17:00:03 -0500 Subject: [PATCH 2/4] Update smriprep/workflows/fit/registration.py Co-authored-by: Chris Markiewicz --- src/smriprep/workflows/fit/registration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/smriprep/workflows/fit/registration.py b/src/smriprep/workflows/fit/registration.py index dfbefa1154..97670d4e06 100644 --- a/src/smriprep/workflows/fit/registration.py +++ b/src/smriprep/workflows/fit/registration.py @@ -218,11 +218,11 @@ def init_register_template_wf( (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'), From 37d5526f73c78a2e0048546c7a6199fd0163575b Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Thu, 12 Dec 2024 00:53:13 -0500 Subject: [PATCH 3/4] FIX: Guard against `Undefined` --- src/smriprep/workflows/fit/registration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smriprep/workflows/fit/registration.py b/src/smriprep/workflows/fit/registration.py index 97670d4e06..d75a12c894 100644 --- a/src/smriprep/workflows/fit/registration.py +++ b/src/smriprep/workflows/fit/registration.py @@ -265,7 +265,7 @@ def _fmt_cohort(template, spec): return template, spec -def _set_reference(image_type, template_t1w, template_t2w): +def _set_reference(image_type, template_t1w, template_t2w=None): """ Determine the normalization reference and whether histogram matching will be used. From e46fc10a9b04ad147560b133946700372e7ad4ec Mon Sep 17 00:00:00 2001 From: Mathias Goncalves Date: Thu, 12 Dec 2024 10:35:30 -0500 Subject: [PATCH 4/4] maint(deps): bump minimum niworkflows --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",