/
registration.py
1873 lines (1716 loc) · 80.5 KB
/
registration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""The ants module provides basic functions for interfacing with ants
functions.
"""
import os
from ...utils.filemanip import ensure_list
from ..base import TraitedSpec, File, Str, traits, InputMultiPath, isdefined
from .base import ANTSCommand, ANTSCommandInputSpec, LOCAL_DEFAULT_NUMBER_OF_THREADS
class ANTSInputSpec(ANTSCommandInputSpec):
dimension = traits.Enum(
3, 2, argstr="%d", position=1, desc="image dimension (2 or 3)"
)
fixed_image = InputMultiPath(
File(exists=True),
mandatory=True,
desc=("image to which the moving image is " "warped"),
)
moving_image = InputMultiPath(
File(exists=True),
argstr="%s",
mandatory=True,
desc=(
"image to apply transformation to "
"(generally a coregistered"
"functional)"
),
)
# Not all metrics are appropriate for all modalities. Also, not all metrics
# are efficeint or appropriate at all resolution levels, Some metrics
# perform well for gross global registraiton, but do poorly for small
# changes (i.e. Mattes), and some metrics do well for small changes but
# don't work well for gross level changes (i.e. 'CC').
#
# This is a two stage registration. in the first stage
# [ 'Mattes', .................]
# ^^^^^^ <- First stage
# Do a unimodal registration of the first elements of the fixed/moving input
# list use the"CC" as the metric.
#
# In the second stage
# [ ....., ['Mattes','CC'] ]
# ^^^^^^^^^^^^^^^ <- Second stage
# Do a multi-modal registration where the first elements of fixed/moving
# input list use 'CC' metric and that is added to 'Mattes' metric result of
# the second elements of the fixed/moving input.
#
# Cost = Sum_i ( metricweight[i] Metric_i ( fixedimage[i], movingimage[i]) )
metric = traits.List(
traits.Enum("CC", "MI", "SMI", "PR", "SSD", "MSQ", "PSE"),
mandatory=True,
desc="",
)
metric_weight = traits.List(
traits.Float(),
value=[1.0],
usedefault=True,
requires=["metric"],
mandatory=True,
desc="the metric weight(s) for each stage. "
"The weights must sum to 1 per stage.",
)
radius = traits.List(
traits.Int(),
requires=["metric"],
mandatory=True,
desc="radius of the region (i.e. number of layers around a voxel/pixel)"
" that is used for computing cross correlation",
)
output_transform_prefix = Str(
"out", usedefault=True, argstr="--output-naming %s", mandatory=True, desc=""
)
transformation_model = traits.Enum(
"Diff",
"Elast",
"Exp",
"Greedy Exp",
"SyN",
argstr="%s",
mandatory=True,
desc="",
)
gradient_step_length = traits.Float(requires=["transformation_model"], desc="")
number_of_time_steps = traits.Int(requires=["gradient_step_length"], desc="")
delta_time = traits.Float(requires=["number_of_time_steps"], desc="")
symmetry_type = traits.Float(requires=["delta_time"], desc="")
use_histogram_matching = traits.Bool(
argstr="%s", default_value=True, usedefault=True
)
number_of_iterations = traits.List(
traits.Int(), argstr="--number-of-iterations %s", sep="x"
)
smoothing_sigmas = traits.List(
traits.Int(), argstr="--gaussian-smoothing-sigmas %s", sep="x"
)
subsampling_factors = traits.List(
traits.Int(), argstr="--subsampling-factors %s", sep="x"
)
affine_gradient_descent_option = traits.List(traits.Float(), argstr="%s")
mi_option = traits.List(traits.Int(), argstr="--MI-option %s", sep="x")
regularization = traits.Enum("Gauss", "DMFFD", argstr="%s", desc="")
regularization_gradient_field_sigma = traits.Float(
requires=["regularization"], desc=""
)
regularization_deformation_field_sigma = traits.Float(
requires=["regularization"], desc=""
)
number_of_affine_iterations = traits.List(
traits.Int(), argstr="--number-of-affine-iterations %s", sep="x"
)
class ANTSOutputSpec(TraitedSpec):
affine_transform = File(exists=True, desc="Affine transform file")
warp_transform = File(exists=True, desc="Warping deformation field")
inverse_warp_transform = File(exists=True, desc="Inverse warping deformation field")
metaheader = File(exists=True, desc="VTK metaheader .mhd file")
metaheader_raw = File(exists=True, desc="VTK metaheader .raw file")
class ANTS(ANTSCommand):
"""ANTS wrapper for registration of images
(old, use Registration instead)
Examples
--------
>>> from nipype.interfaces.ants import ANTS
>>> ants = ANTS()
>>> ants.inputs.dimension = 3
>>> ants.inputs.output_transform_prefix = 'MY'
>>> ants.inputs.metric = ['CC']
>>> ants.inputs.fixed_image = ['T1.nii']
>>> ants.inputs.moving_image = ['resting.nii']
>>> ants.inputs.metric_weight = [1.0]
>>> ants.inputs.radius = [5]
>>> ants.inputs.transformation_model = 'SyN'
>>> ants.inputs.gradient_step_length = 0.25
>>> ants.inputs.number_of_iterations = [50, 35, 15]
>>> ants.inputs.use_histogram_matching = True
>>> ants.inputs.mi_option = [32, 16000]
>>> ants.inputs.regularization = 'Gauss'
>>> ants.inputs.regularization_gradient_field_sigma = 3
>>> ants.inputs.regularization_deformation_field_sigma = 0
>>> ants.inputs.number_of_affine_iterations = [10000,10000,10000,10000,10000]
>>> ants.cmdline
'ANTS 3 --MI-option 32x16000 --image-metric CC[ T1.nii, resting.nii, 1, 5 ] --number-of-affine-iterations \
10000x10000x10000x10000x10000 --number-of-iterations 50x35x15 --output-naming MY --regularization Gauss[3.0,0.0] \
--transformation-model SyN[0.25] --use-Histogram-Matching 1'
"""
_cmd = "ANTS"
input_spec = ANTSInputSpec
output_spec = ANTSOutputSpec
def _image_metric_constructor(self):
retval = []
intensity_based = ["CC", "MI", "SMI", "PR", "SSD", "MSQ"]
point_set_based = ["PSE", "JTB"]
for ii in range(len(self.inputs.moving_image)):
if self.inputs.metric[ii] in intensity_based:
retval.append(
"--image-metric %s[ %s, %s, %g, %d ]"
% (
self.inputs.metric[ii],
self.inputs.fixed_image[ii],
self.inputs.moving_image[ii],
self.inputs.metric_weight[ii],
self.inputs.radius[ii],
)
)
elif self.inputs.metric[ii] == point_set_based:
pass
# retval.append('--image-metric %s[%s, %s, ...'.format(self.inputs.metric[ii],
# self.inputs.fixed_image[ii], self.inputs.moving_image[ii], ...))
return " ".join(retval)
def _transformation_constructor(self):
model = self.inputs.transformation_model
step_length = self.inputs.gradient_step_length
time_step = self.inputs.number_of_time_steps
delta_time = self.inputs.delta_time
symmetry_type = self.inputs.symmetry_type
retval = ["--transformation-model %s" % model]
parameters = []
for elem in (step_length, time_step, delta_time, symmetry_type):
if elem is not traits.Undefined:
parameters.append("%#.2g" % elem)
if len(parameters) > 0:
if len(parameters) > 1:
parameters = ",".join(parameters)
else:
parameters = "".join(parameters)
retval.append("[%s]" % parameters)
return "".join(retval)
def _regularization_constructor(self):
return "--regularization {0}[{1},{2}]".format(
self.inputs.regularization,
self.inputs.regularization_gradient_field_sigma,
self.inputs.regularization_deformation_field_sigma,
)
def _affine_gradient_descent_option_constructor(self):
values = self.inputs.affine_gradient_descent_option
defaults = [0.1, 0.5, 1.0e-4, 1.0e-4]
for ii in range(len(defaults)):
try:
defaults[ii] = values[ii]
except IndexError:
break
parameters = self._format_xarray(
[("%g" % defaults[index]) for index in range(4)]
)
retval = ["--affine-gradient-descent-option", parameters]
return " ".join(retval)
def _format_arg(self, opt, spec, val):
if opt == "moving_image":
return self._image_metric_constructor()
elif opt == "transformation_model":
return self._transformation_constructor()
elif opt == "regularization":
return self._regularization_constructor()
elif opt == "affine_gradient_descent_option":
return self._affine_gradient_descent_option_constructor()
elif opt == "use_histogram_matching":
if self.inputs.use_histogram_matching:
return "--use-Histogram-Matching 1"
else:
return "--use-Histogram-Matching 0"
return super(ANTS, self)._format_arg(opt, spec, val)
def _list_outputs(self):
outputs = self._outputs().get()
outputs["affine_transform"] = os.path.abspath(
self.inputs.output_transform_prefix + "Affine.txt"
)
outputs["warp_transform"] = os.path.abspath(
self.inputs.output_transform_prefix + "Warp.nii.gz"
)
outputs["inverse_warp_transform"] = os.path.abspath(
self.inputs.output_transform_prefix + "InverseWarp.nii.gz"
)
# outputs['metaheader'] = os.path.abspath(self.inputs.output_transform_prefix + 'velocity.mhd')
# outputs['metaheader_raw'] = os.path.abspath(self.inputs.output_transform_prefix + 'velocity.raw')
return outputs
class RegistrationInputSpec(ANTSCommandInputSpec):
dimension = traits.Enum(
3,
2,
argstr="--dimensionality %d",
usedefault=True,
desc="image dimension (2 or 3)",
)
fixed_image = InputMultiPath(
File(exists=True),
mandatory=True,
desc="Image to which the moving_image should be transformed"
"(usually a structural image)",
)
fixed_image_mask = File(
exists=True,
argstr="%s",
max_ver="2.1.0",
xor=["fixed_image_masks"],
desc="Mask used to limit metric sampling region of the fixed image"
"in all stages",
)
fixed_image_masks = InputMultiPath(
traits.Either("NULL", File(exists=True)),
min_ver="2.2.0",
xor=["fixed_image_mask"],
desc="Masks used to limit metric sampling region of the fixed image, defined per registration stage"
'(Use "NULL" to omit a mask at a given stage)',
)
moving_image = InputMultiPath(
File(exists=True),
mandatory=True,
desc="Image that will be registered to the space of fixed_image. This is the"
"image on which the transformations will be applied to",
)
moving_image_mask = File(
exists=True,
requires=["fixed_image_mask"],
max_ver="2.1.0",
xor=["moving_image_masks"],
desc="mask used to limit metric sampling region of the moving image"
"in all stages",
)
moving_image_masks = InputMultiPath(
traits.Either("NULL", File(exists=True)),
min_ver="2.2.0",
xor=["moving_image_mask"],
desc="Masks used to limit metric sampling region of the moving image, defined per registration stage"
'(Use "NULL" to omit a mask at a given stage)',
)
save_state = File(
argstr="--save-state %s",
exists=False,
desc="Filename for saving the internal restorable state of the registration",
)
restore_state = File(
argstr="--restore-state %s",
exists=True,
desc="Filename for restoring the internal restorable state of the registration",
)
initial_moving_transform = InputMultiPath(
File(exists=True),
argstr="%s",
desc="A transform or a list of transforms that should be applied "
"before the registration begins. Note that, when a list is given, "
"the transformations are applied in reverse order.",
xor=["initial_moving_transform_com"],
)
invert_initial_moving_transform = InputMultiPath(
traits.Bool(),
requires=["initial_moving_transform"],
desc="One boolean or a list of booleans that indicate"
"whether the inverse(s) of the transform(s) defined"
"in initial_moving_transform should be used.",
xor=["initial_moving_transform_com"],
)
initial_moving_transform_com = traits.Enum(
0,
1,
2,
argstr="%s",
xor=["initial_moving_transform"],
desc="Align the moving_image and fixed_image before registration using "
"the geometric center of the images (=0), the image intensities (=1), "
"or the origin of the images (=2).",
)
metric_item_trait = traits.Enum("CC", "MeanSquares", "Demons", "GC", "MI", "Mattes")
metric_stage_trait = traits.Either(
metric_item_trait, traits.List(metric_item_trait)
)
metric = traits.List(
metric_stage_trait,
mandatory=True,
desc="the metric(s) to use for each stage. "
"Note that multiple metrics per stage are not supported "
"in ANTS 1.9.1 and earlier.",
)
metric_weight_item_trait = traits.Float(1.0, usedefault=True)
metric_weight_stage_trait = traits.Either(
metric_weight_item_trait, traits.List(metric_weight_item_trait)
)
metric_weight = traits.List(
metric_weight_stage_trait,
value=[1.0],
usedefault=True,
requires=["metric"],
mandatory=True,
desc="the metric weight(s) for each stage. "
"The weights must sum to 1 per stage.",
)
radius_bins_item_trait = traits.Int(5, usedefault=True)
radius_bins_stage_trait = traits.Either(
radius_bins_item_trait, traits.List(radius_bins_item_trait)
)
radius_or_number_of_bins = traits.List(
radius_bins_stage_trait,
value=[5],
usedefault=True,
requires=["metric_weight"],
desc="the number of bins in each stage for the MI and Mattes metric, "
"the radius for other metrics",
)
sampling_strategy_item_trait = traits.Enum("None", "Regular", "Random", None)
sampling_strategy_stage_trait = traits.Either(
sampling_strategy_item_trait, traits.List(sampling_strategy_item_trait)
)
sampling_strategy = traits.List(
trait=sampling_strategy_stage_trait,
requires=["metric_weight"],
desc="the metric sampling strategy (strategies) for each stage",
)
sampling_percentage_item_trait = traits.Either(
traits.Range(low=0.0, high=1.0), None
)
sampling_percentage_stage_trait = traits.Either(
sampling_percentage_item_trait, traits.List(sampling_percentage_item_trait)
)
sampling_percentage = traits.List(
trait=sampling_percentage_stage_trait,
requires=["sampling_strategy"],
desc="the metric sampling percentage(s) to use for each stage",
)
use_estimate_learning_rate_once = traits.List(traits.Bool(), desc="")
use_histogram_matching = traits.Either(
traits.Bool,
traits.List(traits.Bool(argstr="%s")),
default=True,
usedefault=True,
desc="Histogram match the images before registration.",
)
interpolation = traits.Enum(
"Linear",
"NearestNeighbor",
"CosineWindowedSinc",
"WelchWindowedSinc",
"HammingWindowedSinc",
"LanczosWindowedSinc",
"BSpline",
"MultiLabel",
"Gaussian",
argstr="%s",
usedefault=True,
)
interpolation_parameters = traits.Either(
traits.Tuple(traits.Int()), # BSpline (order)
traits.Tuple(
traits.Float(), traits.Float() # Gaussian/MultiLabel (sigma, alpha)
),
)
write_composite_transform = traits.Bool(
argstr="--write-composite-transform %d",
default_value=False,
usedefault=True,
desc="",
)
collapse_output_transforms = traits.Bool(
argstr="--collapse-output-transforms %d",
default_value=True,
usedefault=True, # This should be true for explicit completeness
desc=(
"Collapse output transforms. Specifically, enabling this option "
"combines all adjacent linear transforms and composes all "
"adjacent displacement field transforms before writing the "
"results to disk."
),
)
initialize_transforms_per_stage = traits.Bool(
argstr="--initialize-transforms-per-stage %d",
default_value=False,
usedefault=True, # This should be true for explicit completeness
desc=(
"Initialize linear transforms from the previous stage. By enabling this option, "
"the current linear stage transform is directly intialized from the previous "
"stages linear transform; this allows multiple linear stages to be run where "
"each stage directly updates the estimated linear transform from the previous "
"stage. (e.g. Translation -> Rigid -> Affine). "
),
)
# NOTE: Even though only 0=False and 1=True are allowed, ants uses integer
# values instead of booleans
float = traits.Bool(
argstr="--float %d",
default_value=False,
desc="Use float instead of double for computations.",
)
transforms = traits.List(
traits.Enum(
"Rigid",
"Affine",
"CompositeAffine",
"Similarity",
"Translation",
"BSpline",
"GaussianDisplacementField",
"TimeVaryingVelocityField",
"TimeVaryingBSplineVelocityField",
"SyN",
"BSplineSyN",
"Exponential",
"BSplineExponential",
),
argstr="%s",
mandatory=True,
)
# TODO: input checking and allow defaults
# All parameters must be specified for BSplineDisplacementField, TimeVaryingBSplineVelocityField, BSplineSyN,
# Exponential, and BSplineExponential. EVEN DEFAULTS!
transform_parameters = traits.List(
traits.Either(
traits.Tuple(traits.Float()), # Translation, Rigid, Affine,
# CompositeAffine, Similarity
traits.Tuple(
traits.Float(), # GaussianDisplacementField, SyN
traits.Float(),
traits.Float(),
),
traits.Tuple(
traits.Float(), # BSplineSyn,
traits.Int(), # BSplineDisplacementField,
traits.Int(), # TimeVaryingBSplineVelocityField
traits.Int(),
),
traits.Tuple(
traits.Float(), # TimeVaryingVelocityField
traits.Int(),
traits.Float(),
traits.Float(),
traits.Float(),
traits.Float(),
),
traits.Tuple(
traits.Float(), # Exponential
traits.Float(),
traits.Float(),
traits.Int(),
),
traits.Tuple(
traits.Float(), # BSplineExponential
traits.Int(),
traits.Int(),
traits.Int(),
traits.Int(),
),
)
)
restrict_deformation = traits.List(
traits.List(traits.Enum(0, 1)),
desc=(
"This option allows the user to restrict the optimization of "
"the displacement field, translation, rigid or affine transform "
"on a per-component basis. For example, if one wants to limit "
"the deformation or rotation of 3-D volume to the first two "
"dimensions, this is possible by specifying a weight vector of "
"'1x1x0' for a deformation field or '1x1x0x1x1x0' for a rigid "
"transformation. Low-dimensional restriction only works if "
"there are no preceding transformations."
),
)
# Convergence flags
number_of_iterations = traits.List(traits.List(traits.Int()))
smoothing_sigmas = traits.List(traits.List(traits.Float()), mandatory=True)
sigma_units = traits.List(
traits.Enum("mm", "vox"),
requires=["smoothing_sigmas"],
desc="units for smoothing sigmas",
)
shrink_factors = traits.List(traits.List(traits.Int()), mandatory=True)
convergence_threshold = traits.List(
trait=traits.Float(),
value=[1e-6],
minlen=1,
requires=["number_of_iterations"],
usedefault=True,
)
convergence_window_size = traits.List(
trait=traits.Int(),
value=[10],
minlen=1,
requires=["convergence_threshold"],
usedefault=True,
)
# Output flags
output_transform_prefix = Str("transform", usedefault=True, argstr="%s", desc="")
output_warped_image = traits.Either(traits.Bool, File(), hash_files=False, desc="")
output_inverse_warped_image = traits.Either(
traits.Bool, File(), hash_files=False, requires=["output_warped_image"], desc=""
)
winsorize_upper_quantile = traits.Range(
low=0.0,
high=1.0,
value=1.0,
argstr="%s",
usedefault=True,
desc="The Upper quantile to clip image ranges",
)
winsorize_lower_quantile = traits.Range(
low=0.0,
high=1.0,
value=0.0,
argstr="%s",
usedefault=True,
desc="The Lower quantile to clip image ranges",
)
verbose = traits.Bool(argstr="-v", default_value=False, usedefault=True)
class RegistrationOutputSpec(TraitedSpec):
forward_transforms = traits.List(
File(exists=True), desc="List of output transforms for forward registration"
)
reverse_forward_transforms = traits.List(
File(exists=True),
desc="List of output transforms for forward registration reversed for antsApplyTransform",
)
reverse_transforms = traits.List(
File(exists=True), desc="List of output transforms for reverse registration"
)
forward_invert_flags = traits.List(
traits.Bool(), desc="List of flags corresponding to the forward transforms"
)
reverse_forward_invert_flags = traits.List(
traits.Bool(),
desc="List of flags corresponding to the forward transforms reversed for antsApplyTransform",
)
reverse_invert_flags = traits.List(
traits.Bool(), desc="List of flags corresponding to the reverse transforms"
)
composite_transform = File(exists=True, desc="Composite transform file")
inverse_composite_transform = File(desc="Inverse composite transform file")
warped_image = File(desc="Outputs warped image")
inverse_warped_image = File(desc="Outputs the inverse of the warped image")
save_state = File(desc="The saved registration state to be restored")
metric_value = traits.Float(desc="the final value of metric")
elapsed_time = traits.Float(desc="the total elapsed time as reported by ANTs")
class Registration(ANTSCommand):
"""ANTs Registration command for registration of images
`antsRegistration <http://stnava.github.io/ANTs/>`_ registers a ``moving_image`` to a ``fixed_image``,
using a predefined (sequence of) cost function(s) and transformation operations.
The cost function is defined using one or more 'metrics', specifically
local cross-correlation (``CC``), Mean Squares (``MeanSquares``), Demons (``Demons``),
global correlation (``GC``), or Mutual Information (``Mattes`` or ``MI``).
ANTS can use both linear (``Translation``, ``Rigid``, ``Affine``, ``CompositeAffine``,
or ``Translation``) and non-linear transformations (``BSpline``, ``GaussianDisplacementField``,
``TimeVaryingVelocityField``, ``TimeVaryingBSplineVelocityField``, ``SyN``, ``BSplineSyN``,
``Exponential``, or ``BSplineExponential``). Usually, registration is done in multiple
*stages*. For example first an Affine, then a Rigid, and ultimately a non-linear
(Syn)-transformation.
antsRegistration can be initialized using one ore more transforms from moving_image
to fixed_image with the ``initial_moving_transform``-input. For example, when you
already have a warpfield that corrects for geometrical distortions in an EPI (functional) image,
that you want to apply before an Affine registration to a structural image.
You could put this transform into 'intial_moving_transform'.
The Registration-interface can output the resulting transform(s) that map moving_image to
fixed_image in a single file as a ``composite_transform`` (if ``write_composite_transform``
is set to ``True``), or a list of transforms as ``forwards_transforms``. It can also output
inverse transforms (from ``fixed_image`` to ``moving_image``) in a similar fashion using
``inverse_composite_transform``. Note that the order of ``forward_transforms`` is in 'natural'
order: the first element should be applied first, the last element should be applied last.
Note, however, that ANTS tools always apply lists of transformations in reverse order (the last
transformation in the list is applied first). Therefore, if the output forward_transforms
is a list, one can not directly feed it into, for example, ``ants.ApplyTransforms``. To
make ``ants.ApplyTransforms`` apply the transformations in the same order as ``ants.Registration``,
you have to provide the list of transformations in reverse order from ``forward_transforms``.
``reverse_forward_transforms`` outputs ``forward_transforms`` in reverse order and can be used for
this purpose. Note also that, because ``composite_transform`` is always a single file, this
output is preferred for most use-cases.
More information can be found in the `ANTS
manual <https://sourceforge.net/projects/advants/files/Documentation/ants.pdf/download>`_.
See below for some useful examples.
Examples
--------
Set up a Registration node with some default settings. This Node registers
'fixed1.nii' to 'moving1.nii' by first fitting a linear 'Affine' transformation, and
then a non-linear 'SyN' transformation, both using the Mutual Information-cost
metric.
The registration is initialized by first applying the (linear) transform
trans.mat.
>>> import copy, pprint
>>> from nipype.interfaces.ants import Registration
>>> reg = Registration()
>>> reg.inputs.fixed_image = 'fixed1.nii'
>>> reg.inputs.moving_image = 'moving1.nii'
>>> reg.inputs.output_transform_prefix = "output_"
>>> reg.inputs.initial_moving_transform = 'trans.mat'
>>> reg.inputs.transforms = ['Affine', 'SyN']
>>> reg.inputs.transform_parameters = [(2.0,), (0.25, 3.0, 0.0)]
>>> reg.inputs.number_of_iterations = [[1500, 200], [100, 50, 30]]
>>> reg.inputs.dimension = 3
>>> reg.inputs.write_composite_transform = True
>>> reg.inputs.collapse_output_transforms = False
>>> reg.inputs.initialize_transforms_per_stage = False
>>> reg.inputs.metric = ['Mattes']*2
>>> reg.inputs.metric_weight = [1]*2 # Default (value ignored currently by ANTs)
>>> reg.inputs.radius_or_number_of_bins = [32]*2
>>> reg.inputs.sampling_strategy = ['Random', None]
>>> reg.inputs.sampling_percentage = [0.05, None]
>>> reg.inputs.convergence_threshold = [1.e-8, 1.e-9]
>>> reg.inputs.convergence_window_size = [20]*2
>>> reg.inputs.smoothing_sigmas = [[1,0], [2,1,0]]
>>> reg.inputs.sigma_units = ['vox'] * 2
>>> reg.inputs.shrink_factors = [[2,1], [3,2,1]]
>>> reg.inputs.use_estimate_learning_rate_once = [True, True]
>>> reg.inputs.use_histogram_matching = [True, True] # This is the default
>>> reg.inputs.output_warped_image = 'output_warped_image.nii.gz'
>>> reg.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 0 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
>>> reg.run() # doctest: +SKIP
Same as reg1, but first invert the initial transform ('trans.mat') before applying it.
>>> reg.inputs.invert_initial_moving_transform = True
>>> reg1 = copy.deepcopy(reg)
>>> reg1.inputs.winsorize_lower_quantile = 0.025
>>> reg1.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.025, 1.0 ] --write-composite-transform 1'
>>> reg1.run() # doctest: +SKIP
Clip extremely high intensity data points using winsorize_upper_quantile. All data points
higher than the 0.975 quantile are set to the value of the 0.975 quantile.
>>> reg2 = copy.deepcopy(reg)
>>> reg2.inputs.winsorize_upper_quantile = 0.975
>>> reg2.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 0.975 ] --write-composite-transform 1'
Clip extremely low intensity data points using winsorize_lower_quantile. All data points
lower than the 0.025 quantile are set to the original value at the 0.025 quantile.
>>> reg3 = copy.deepcopy(reg)
>>> reg3.inputs.winsorize_lower_quantile = 0.025
>>> reg3.inputs.winsorize_upper_quantile = 0.975
>>> reg3.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.025, 0.975 ] --write-composite-transform 1'
Use float instead of double for computations (saves memory usage)
>>> reg3a = copy.deepcopy(reg)
>>> reg3a.inputs.float = True
>>> reg3a.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --float 1 \
--initial-moving-transform [ trans.mat, 1 ] --initialize-transforms-per-stage 0 --interpolation Linear \
--output [ output_, output_warped_image.nii.gz ] --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 1'
Force to use double instead of float for computations (more precision and memory usage).
>>> reg3b = copy.deepcopy(reg)
>>> reg3b.inputs.float = False
>>> reg3b.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --float 0 \
--initial-moving-transform [ trans.mat, 1 ] --initialize-transforms-per-stage 0 --interpolation Linear \
--output [ output_, output_warped_image.nii.gz ] --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 1'
'collapse_output_transforms' can be used to put all transformation in a single 'composite_transform'-
file. Note that forward_transforms will now be an empty list.
>>> # Test collapse transforms flag
>>> reg4 = copy.deepcopy(reg)
>>> reg4.inputs.save_state = 'trans.mat'
>>> reg4.inputs.restore_state = 'trans.mat'
>>> reg4.inputs.initialize_transforms_per_stage = True
>>> reg4.inputs.collapse_output_transforms = True
>>> outputs = reg4._list_outputs()
>>> pprint.pprint(outputs) # doctest: +ELLIPSIS,
{'composite_transform': '...data/output_Composite.h5',
'elapsed_time': <undefined>,
'forward_invert_flags': [],
'forward_transforms': [],
'inverse_composite_transform': '...data/output_InverseComposite.h5',
'inverse_warped_image': <undefined>,
'metric_value': <undefined>,
'reverse_forward_invert_flags': [],
'reverse_forward_transforms': [],
'reverse_invert_flags': [],
'reverse_transforms': [],
'save_state': '...data/trans.mat',
'warped_image': '...data/output_warped_image.nii.gz'}
>>> reg4.cmdline
'antsRegistration --collapse-output-transforms 1 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 1 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--restore-state trans.mat --save-state trans.mat --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 1'
>>> # Test collapse transforms flag
>>> reg4b = copy.deepcopy(reg4)
>>> reg4b.inputs.write_composite_transform = False
>>> outputs = reg4b._list_outputs()
>>> pprint.pprint(outputs) # doctest: +ELLIPSIS,
{'composite_transform': <undefined>,
'elapsed_time': <undefined>,
'forward_invert_flags': [False, False],
'forward_transforms': ['...data/output_0GenericAffine.mat',
'...data/output_1Warp.nii.gz'],
'inverse_composite_transform': <undefined>,
'inverse_warped_image': <undefined>,
'metric_value': <undefined>,
'reverse_forward_invert_flags': [False, False],
'reverse_forward_transforms': ['...data/output_1Warp.nii.gz',
'...data/output_0GenericAffine.mat'],
'reverse_invert_flags': [True, False],
'reverse_transforms': ['...data/output_0GenericAffine.mat', \
'...data/output_1InverseWarp.nii.gz'],
'save_state': '...data/trans.mat',
'warped_image': '...data/output_warped_image.nii.gz'}
>>> reg4b.aggregate_outputs() # doctest: +SKIP
>>> reg4b.cmdline
'antsRegistration --collapse-output-transforms 1 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 1 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--restore-state trans.mat --save-state trans.mat --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 0'
One can use multiple similarity metrics in a single registration stage.The Node below first
performs a linear registation using only the Mutual Information ('Mattes')-metric.
In a second stage, it performs a non-linear registration ('Syn') using both a
Mutual Information and a local cross-correlation ('CC')-metric. Both metrics are weighted
equally ('metric_weight' is .5 for both). The Mutual Information- metric uses 32 bins.
The local cross-correlations (correlations between every voxel's neighborhoods) is computed
with a radius of 4.
>>> # Test multiple metrics per stage
>>> reg5 = copy.deepcopy(reg)
>>> reg5.inputs.fixed_image = 'fixed1.nii'
>>> reg5.inputs.moving_image = 'moving1.nii'
>>> reg5.inputs.metric = ['Mattes', ['Mattes', 'CC']]
>>> reg5.inputs.metric_weight = [1, [.5,.5]]
>>> reg5.inputs.radius_or_number_of_bins = [32, [32, 4] ]
>>> reg5.inputs.sampling_strategy = ['Random', None] # use default strategy in second stage
>>> reg5.inputs.sampling_percentage = [0.05, [0.05, 0.10]]
>>> reg5.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 0.5, 32, None, 0.05 ] \
--metric CC[ fixed1.nii, moving1.nii, 0.5, 4, None, 0.1 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
ANTS Registration can also use multiple modalities to perform the registration. Here it is assumed
that fixed1.nii and fixed2.nii are in the same space, and so are moving1.nii and
moving2.nii. First, a linear registration is performed matching fixed1.nii to moving1.nii,
then a non-linear registration is performed to match fixed2.nii to moving2.nii, starting from
the transformation of the first step.
>>> # Test multiple inputS
>>> reg6 = copy.deepcopy(reg5)
>>> reg6.inputs.fixed_image = ['fixed1.nii', 'fixed2.nii']
>>> reg6.inputs.moving_image = ['moving1.nii', 'moving2.nii']
>>> reg6.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 0.5, 32, None, 0.05 ] \
--metric CC[ fixed2.nii, moving2.nii, 0.5, 4, None, 0.1 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
Different methods can be used for the interpolation when applying transformations.
>>> # Test Interpolation Parameters (BSpline)
>>> reg7a = copy.deepcopy(reg)
>>> reg7a.inputs.interpolation = 'BSpline'
>>> reg7a.inputs.interpolation_parameters = (3,)
>>> reg7a.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation BSpline[ 3 ] --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform SyN[ 0.25, 3.0, 0.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
>>> # Test Interpolation Parameters (MultiLabel/Gaussian)
>>> reg7b = copy.deepcopy(reg)
>>> reg7b.inputs.interpolation = 'Gaussian'
>>> reg7b.inputs.interpolation_parameters = (1.0, 1.0)
>>> reg7b.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Gaussian[ 1.0, 1.0 ] \
--output [ output_, output_warped_image.nii.gz ] --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 1'
BSplineSyN non-linear registration with custom parameters.
>>> # Test Extended Transform Parameters
>>> reg8 = copy.deepcopy(reg)
>>> reg8.inputs.transforms = ['Affine', 'BSplineSyN']
>>> reg8.inputs.transform_parameters = [(2.0,), (0.25, 26, 0, 3)]
>>> reg8.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --transform BSplineSyN[ 0.25, 26, 0, 3 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] --convergence [ 100x50x30, 1e-09, 20 ] \
--smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 --use-estimate-learning-rate-once 1 \
--use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
Mask the fixed image in the second stage of the registration (but not the first).
>>> # Test masking
>>> reg9 = copy.deepcopy(reg)
>>> reg9.inputs.fixed_image_masks = ['NULL', 'fixed1.nii']
>>> reg9.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform [ trans.mat, 1 ] \
--initialize-transforms-per-stage 0 --interpolation Linear --output [ output_, output_warped_image.nii.gz ] \
--transform Affine[ 2.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] \
--convergence [ 1500x200, 1e-08, 20 ] --smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --masks [ NULL, NULL ] \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --masks [ fixed1.nii, NULL ] \
--winsorize-image-intensities [ 0.0, 1.0 ] --write-composite-transform 1'
Here we use both a warpfield and a linear transformation, before registration commences. Note that
the first transformation that needs to be applied ('ants_Warp.nii.gz') is last in the list of
'initial_moving_transform'.
>>> # Test initialization with multiple transforms matrices (e.g., unwarp and affine transform)
>>> reg10 = copy.deepcopy(reg)
>>> reg10.inputs.initial_moving_transform = ['func_to_struct.mat', 'ants_Warp.nii.gz']
>>> reg10.inputs.invert_initial_moving_transform = [False, False]
>>> reg10.cmdline
'antsRegistration --collapse-output-transforms 0 --dimensionality 3 --initial-moving-transform \
[ func_to_struct.mat, 0 ] [ ants_Warp.nii.gz, 0 ] --initialize-transforms-per-stage 0 --interpolation Linear \
--output [ output_, output_warped_image.nii.gz ] --transform Affine[ 2.0 ] \
--metric Mattes[ fixed1.nii, moving1.nii, 1, 32, Random, 0.05 ] --convergence [ 1500x200, 1e-08, 20 ] \
--smoothing-sigmas 1.0x0.0vox --shrink-factors 2x1 --use-estimate-learning-rate-once 1 --use-histogram-matching 1 \
--transform SyN[ 0.25, 3.0, 0.0 ] --metric Mattes[ fixed1.nii, moving1.nii, 1, 32 ] \
--convergence [ 100x50x30, 1e-09, 20 ] --smoothing-sigmas 2.0x1.0x0.0vox --shrink-factors 3x2x1 \
--use-estimate-learning-rate-once 1 --use-histogram-matching 1 --winsorize-image-intensities [ 0.0, 1.0 ] \
--write-composite-transform 1'
"""
DEF_SAMPLING_STRATEGY = "None"
"""The default sampling strategy argument."""
_cmd = "antsRegistration"
input_spec = RegistrationInputSpec
output_spec = RegistrationOutputSpec
_quantilesDone = False
_linear_transform_names = [
"Rigid",
"Affine",