Skip to content

Commit 0d4ea0e

Browse files
committed
update ants registration example
1 parent 3f2612a commit 0d4ea0e

File tree

2 files changed

+213
-26
lines changed

2 files changed

+213
-26
lines changed

examples/smri_ants_registration.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,43 @@
5757
]
5858

5959
"""
60-
3. Define the parameters of the registration
60+
3. Define the parameters of the registration. Settings are
61+
saved in `./smri_ants_registration_settings.json`.
6162
"""
6263

63-
reg = Registration()
64+
reg = Registration(from_file='./smri_ants_registration_settings.json')
6465
reg.inputs.fixed_image = input_images[0]
6566
reg.inputs.moving_image = input_images[1]
66-
reg.inputs.output_transform_prefix = 'thisTransform'
67-
reg.inputs.output_warped_image = 'INTERNAL_WARPED.nii.gz'
68-
69-
reg.inputs.output_transform_prefix = "output_"
70-
reg.inputs.transforms = ['Translation', 'Rigid', 'Affine', 'SyN']
71-
reg.inputs.transform_parameters = [(0.1,), (0.1,), (0.1,), (0.2, 3.0, 0.0)]
72-
reg.inputs.number_of_iterations = ([[10000, 111110, 11110]] * 3 +
73-
[[100, 50, 30]])
74-
reg.inputs.dimension = 3
75-
reg.inputs.write_composite_transform = True
76-
reg.inputs.collapse_output_transforms = False
77-
reg.inputs.metric = ['Mattes'] * 3 + [['Mattes', 'CC']]
78-
reg.inputs.metric_weight = [1] * 3 + [[0.5, 0.5]]
79-
reg.inputs.radius_or_number_of_bins = [32] * 3 + [[32, 4]]
80-
reg.inputs.sampling_strategy = ['Regular'] * 3 + [[None, None]]
81-
reg.inputs.sampling_percentage = [0.3] * 3 + [[None, None]]
82-
reg.inputs.convergence_threshold = [1.e-8] * 3 + [-0.01]
83-
reg.inputs.convergence_window_size = [20] * 3 + [5]
84-
reg.inputs.smoothing_sigmas = [[4, 2, 1]] * 3 + [[1, 0.5, 0]]
85-
reg.inputs.sigma_units = ['vox'] * 4
86-
reg.inputs.shrink_factors = [[6, 4, 2]] + [[3, 2, 1]] * 2 + [[4, 2, 1]]
87-
reg.inputs.use_estimate_learning_rate_once = [True] * 4
88-
reg.inputs.use_histogram_matching = [False] * 3 + [True]
89-
reg.inputs.initial_moving_transform_com = True
9067

68+
"""
69+
Alternatively to the use of the `from_file` feature to load ANTs settings,
70+
the user can manually set all those inputs instead::
71+
72+
reg.inputs.output_transform_prefix = 'thisTransform'
73+
reg.inputs.output_warped_image = 'INTERNAL_WARPED.nii.gz'
74+
reg.inputs.output_transform_prefix = "output_"
75+
reg.inputs.transforms = ['Translation', 'Rigid', 'Affine', 'SyN']
76+
reg.inputs.transform_parameters = [(0.1,), (0.1,), (0.1,), (0.2, 3.0, 0.0)]
77+
reg.inputs.number_of_iterations = ([[10000, 111110, 11110]] * 3 +
78+
[[100, 50, 30]])
79+
reg.inputs.dimension = 3
80+
reg.inputs.write_composite_transform = True
81+
reg.inputs.collapse_output_transforms = False
82+
reg.inputs.metric = ['Mattes'] * 3 + [['Mattes', 'CC']]
83+
reg.inputs.metric_weight = [1] * 3 + [[0.5, 0.5]]
84+
reg.inputs.radius_or_number_of_bins = [32] * 3 + [[32, 4]]
85+
reg.inputs.sampling_strategy = ['Regular'] * 3 + [[None, None]]
86+
reg.inputs.sampling_percentage = [0.3] * 3 + [[None, None]]
87+
reg.inputs.convergence_threshold = [1.e-8] * 3 + [-0.01]
88+
reg.inputs.convergence_window_size = [20] * 3 + [5]
89+
reg.inputs.smoothing_sigmas = [[4, 2, 1]] * 3 + [[1, 0.5, 0]]
90+
reg.inputs.sigma_units = ['vox'] * 4
91+
reg.inputs.shrink_factors = [[6, 4, 2]] + [[3, 2, 1]] * 2 + [[4, 2, 1]]
92+
reg.inputs.use_estimate_learning_rate_once = [True] * 4
93+
reg.inputs.use_histogram_matching = [False] * 3 + [True]
94+
reg.inputs.initial_moving_transform_com = True
95+
96+
"""
9197
print(reg.cmdline)
9298

9399

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
"convergence_window_size": [
3+
20,
4+
20,
5+
20,
6+
5
7+
],
8+
"winsorize_lower_quantile": 0.0,
9+
"output_transform_prefix": "output_",
10+
"transforms": [
11+
"Translation",
12+
"Rigid",
13+
"Affine",
14+
"SyN"
15+
],
16+
"initial_moving_transform_com": true,
17+
"metric_weight": [
18+
1.0,
19+
1.0,
20+
1.0,
21+
[
22+
0.5,
23+
0.5
24+
]
25+
],
26+
"sigma_units": [
27+
"vox",
28+
"vox",
29+
"vox",
30+
"vox"
31+
],
32+
"convergence_threshold": [
33+
1e-08,
34+
1e-08,
35+
1e-08,
36+
-0.01
37+
],
38+
"sampling_strategy": [
39+
"Regular",
40+
"Regular",
41+
"Regular",
42+
[
43+
null,
44+
null
45+
]
46+
],
47+
"shrink_factors": [
48+
[
49+
6,
50+
4,
51+
2
52+
],
53+
[
54+
3,
55+
2,
56+
1
57+
],
58+
[
59+
3,
60+
2,
61+
1
62+
],
63+
[
64+
4,
65+
2,
66+
1
67+
]
68+
],
69+
"winsorize_upper_quantile": 1.0,
70+
"metric": [
71+
"Mattes",
72+
"Mattes",
73+
"Mattes",
74+
[
75+
"Mattes",
76+
"CC"
77+
]
78+
],
79+
"interpolation": "Linear",
80+
"ignore_exception": false,
81+
"use_estimate_learning_rate_once": [
82+
true,
83+
true,
84+
true,
85+
true
86+
],
87+
"terminal_output": "stream",
88+
"write_composite_transform": true,
89+
"initialize_transforms_per_stage": false,
90+
"num_threads": 1,
91+
"output_warped_image": "INTERNAL_WARPED.nii.gz",
92+
"sampling_percentage": [
93+
0.3,
94+
0.3,
95+
0.3,
96+
[
97+
null,
98+
null
99+
]
100+
],
101+
"number_of_iterations": [
102+
[
103+
10000,
104+
111110,
105+
11110
106+
],
107+
[
108+
10000,
109+
111110,
110+
11110
111+
],
112+
[
113+
10000,
114+
111110,
115+
11110
116+
],
117+
[
118+
100,
119+
50,
120+
30
121+
]
122+
],
123+
"radius_or_number_of_bins": [
124+
32,
125+
32,
126+
32,
127+
[
128+
32,
129+
4
130+
]
131+
],
132+
"environ": {
133+
"NSLOTS": "1"
134+
},
135+
"smoothing_sigmas": [
136+
[
137+
4.0,
138+
2.0,
139+
1.0
140+
],
141+
[
142+
4.0,
143+
2.0,
144+
1.0
145+
],
146+
[
147+
4.0,
148+
2.0,
149+
1.0
150+
],
151+
[
152+
1.0,
153+
0.5,
154+
0.0
155+
]
156+
],
157+
"use_histogram_matching": [
158+
false,
159+
false,
160+
false,
161+
true
162+
],
163+
"transform_parameters": [
164+
[
165+
0.1
166+
],
167+
[
168+
0.1
169+
],
170+
[
171+
0.1
172+
],
173+
[
174+
0.2,
175+
3.0,
176+
0.0
177+
]
178+
],
179+
"dimension": 3,
180+
"collapse_output_transforms": false
181+
}

0 commit comments

Comments
 (0)