Skip to content

Commit faad78f

Browse files
committed
ENH: Support spatial normalization to alternative modalities
1 parent 87e5e88 commit faad78f

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

src/smriprep/workflows/fit/registration.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838

3939
def init_register_template_wf(
4040
*,
41-
sloppy,
42-
omp_nthreads,
43-
templates,
41+
sloppy: bool,
42+
omp_nthreads: int,
43+
templates: list[str],
44+
image_type: str = 'T1w',
4445
name='register_template_wf',
4546
):
4647
"""
@@ -89,6 +90,8 @@ def init_register_template_wf(
8990
input domain to enable standardization of lesioned brains.
9091
template
9192
Template name and specification
93+
image_type
94+
Moving image modality
9295
9396
Outputs
9497
-------
@@ -170,6 +173,15 @@ def init_register_template_wf(
170173
run_without_submitting=True,
171174
)
172175

176+
set_reference = pe.Node(
177+
niu.Function(
178+
function=_set_reference,
179+
output_names=['reference_type', 'use_histogram_matching'],
180+
),
181+
name='set_reference',
182+
)
183+
set_reference.inputs.image_type = image_type
184+
173185
# With the improvements from nipreps/niworkflows#342 this truncation is now necessary
174186
trunc_mov = pe.Node(
175187
ants.ImageMath(operation='TruncateImageIntensity', op2='0.01 0.999 256'),
@@ -203,6 +215,14 @@ def init_register_template_wf(
203215
('name', 'template'),
204216
('spec', 'template_spec'),
205217
]),
218+
(tf_select, set_reference, [
219+
('t1w_file', 'template_t1w'),
220+
('t2w_file', 'template_t2w'),
221+
])
222+
(set_reference, registration, [
223+
('reference_type', 'reference'),
224+
('use_histogram_matching', 'use_histogram_matching'),
225+
])
206226
(split_desc, registration, [
207227
('name', 'template'),
208228
('spec', 'template_spec'),
@@ -243,3 +263,27 @@ def _fmt_cohort(template, spec):
243263
if cohort is not None:
244264
template = f'{template}:cohort-{cohort}'
245265
return template, spec
266+
267+
268+
def _set_reference(image_type, template_t1w, template_t2w):
269+
"""
270+
Determine the normalization reference and whether histogram matching will be used.
271+
272+
Parameters
273+
----------
274+
image_type : MR image type of anatomical reference (T1w, T2w)
275+
template_t1w : T1w file
276+
template_t2w : T2w file or undefined
277+
278+
Returns
279+
-------
280+
reference_type : modality of template reference (T1w, T2w)
281+
histogram_matching : False when image_type does not match reference image, otherwise Undefined
282+
"""
283+
from nipype.interfaces.base import Undefined
284+
285+
if image_type == 'T2w':
286+
if template_t2w:
287+
return 'T2w', Undefined
288+
return 'T1w', False
289+
return 'T1w', Undefined

0 commit comments

Comments
 (0)