Skip to content

Commit

Permalink
ENH: Support spatial normalization to alternative modalities
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Dec 11, 2024
1 parent bbd0faf commit 1f6f615
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions smriprep/workflows/fit/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
):
"""
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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

0 comments on commit 1f6f615

Please sign in to comment.