|
38 | 38 |
|
39 | 39 | def init_register_template_wf( |
40 | 40 | *, |
41 | | - sloppy, |
42 | | - omp_nthreads, |
43 | | - templates, |
| 41 | + sloppy: bool, |
| 42 | + omp_nthreads: int, |
| 43 | + templates: list[str], |
| 44 | + image_type: str = 'T1w', |
44 | 45 | name='register_template_wf', |
45 | 46 | ): |
46 | 47 | """ |
@@ -89,6 +90,8 @@ def init_register_template_wf( |
89 | 90 | input domain to enable standardization of lesioned brains. |
90 | 91 | template |
91 | 92 | Template name and specification |
| 93 | + image_type |
| 94 | + Moving image modality |
92 | 95 |
|
93 | 96 | Outputs |
94 | 97 | ------- |
@@ -170,6 +173,15 @@ def init_register_template_wf( |
170 | 173 | run_without_submitting=True, |
171 | 174 | ) |
172 | 175 |
|
| 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 | + |
173 | 185 | # With the improvements from nipreps/niworkflows#342 this truncation is now necessary |
174 | 186 | trunc_mov = pe.Node( |
175 | 187 | ants.ImageMath(operation='TruncateImageIntensity', op2='0.01 0.999 256'), |
@@ -203,6 +215,14 @@ def init_register_template_wf( |
203 | 215 | ('name', 'template'), |
204 | 216 | ('spec', 'template_spec'), |
205 | 217 | ]), |
| 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 | + ]) |
206 | 226 | (split_desc, registration, [ |
207 | 227 | ('name', 'template'), |
208 | 228 | ('spec', 'template_spec'), |
@@ -243,3 +263,27 @@ def _fmt_cohort(template, spec): |
243 | 263 | if cohort is not None: |
244 | 264 | template = f'{template}:cohort-{cohort}' |
245 | 265 | 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