Skip to content

Commit 6449adf

Browse files
committed
rf: use ants' CompositeTransformUtil
Support is now available after ANTsX/ANTs#1827 was fixed
1 parent 630786a commit 6449adf

File tree

1 file changed

+1
-43
lines changed

1 file changed

+1
-43
lines changed

nibabies/workflows/anatomical/registration.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,8 @@ def init_concat_registrations_wf(
451451
CompositeTransformUtil(process='assemble', out_file='anat2std.h5'),
452452
name='assemble_anat2std',
453453
)
454-
# https://github.com/ANTsX/ANTs/issues/1827
455-
# Until CompositeTransformUtil accepts warps as first transform,
456-
# Use SimpleITK to concatenate
457454
assemble_std2anat = pe.Node(
458-
niu.Function(function=_create_inverse_composite, output_names=['out_file']),
455+
CompositeTransformUtil(process='assemble', out_file='std2anat.h5'),
459456
name='assemble_std2anat',
460457
)
461458

@@ -502,42 +499,3 @@ def init_concat_registrations_wf(
502499
]) # fmt:skip
503500

504501
return workflow
505-
506-
507-
def _create_inverse_composite(in_file, out_file='inverse_composite.h5'):
508-
"""
509-
Build a composite transform with SimpleITK.
510-
511-
This serves as a workaround for a bug in ANTs's CompositeTransformUtil
512-
https://github.com/ANTsX/ANTs/issues/1827
513-
where composite transforms cannot be created with a displacement field placed first.
514-
515-
Parameters
516-
----------
517-
in_file : list of str
518-
List of input transforms to concatenate into a composite transform.
519-
out_file : str, optional
520-
File to write the composite transform to.
521-
522-
Returns
523-
-------
524-
out_file : str
525-
Absolute path to the composite transform.
526-
"""
527-
528-
from pathlib import Path
529-
530-
import SimpleITK as sitk
531-
532-
composite = sitk.CompositeTransform(3)
533-
for xfm_file in in_file:
534-
if xfm_file.endswith('mat'):
535-
xfm = sitk.ReadTransform(xfm_file)
536-
else:
537-
xfm = sitk.DisplacementFieldTransform(sitk.ReadImage(xfm_file))
538-
539-
composite.AddTransform(xfm)
540-
541-
out_file = str(Path(out_file).absolute())
542-
sitk.WriteTransform(composite, out_file)
543-
return out_file

0 commit comments

Comments
 (0)