Skip to content

ENH: Support spatial normalization to alternative modalities #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 47 additions & 3 deletions src/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=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
Loading