|
7 | 7 |
|
8 | 8 | import ants
|
9 | 9 |
|
10 |
| -def convergence_monitoring(values, window_size=10): |
11 |
| - if len(values) >= window_size: |
12 |
| - u = np.linspace(0.0, 1.0, num=window_size) |
13 |
| - scattered_data = np.expand_dims(values[-window_size:], axis=-1) |
14 |
| - parametric_data = np.expand_dims(u, axis=-1) |
15 |
| - spacing = 1 / (window_size-1) |
16 |
| - bspline_line = ants.fit_bspline_object_to_scattered_data(scattered_data, parametric_data, |
17 |
| - parametric_domain_origin=[0.0], parametric_domain_spacing=[spacing], |
18 |
| - parametric_domain_size=[window_size], number_of_fitting_levels=1, mesh_size=1, |
19 |
| - spline_order=1) |
20 |
| - bspline_slope = -(bspline_line[1][0] - bspline_line[0][0]) / spacing |
21 |
| - return(bspline_slope) |
22 |
| - else: |
23 |
| - return None |
24 |
| - |
25 |
| - |
26 | 10 | def fit_transform_to_paired_points(moving_points,
|
27 | 11 | fixed_points,
|
28 | 12 | transform_type="affine",
|
@@ -130,17 +114,6 @@ def fit_transform_to_paired_points(moving_points,
|
130 | 114 | >>> xfrm = ants.fit_transform_to_paired_points(moving, fixed, transform_type="diffeo", domain_image=domain_image, number_of_fitting_levels=6)
|
131 | 115 | """
|
132 | 116 |
|
133 |
| - def polar_decomposition(X): |
134 |
| - U, d, V = np.linalg.svd(X, full_matrices=False) |
135 |
| - P = np.matmul(U, np.matmul(np.diag(d), np.transpose(U))) |
136 |
| - Z = np.matmul(U, V) |
137 |
| - if np.linalg.det(Z) < 0: |
138 |
| - n = X.shape[0] |
139 |
| - reflection_matrix = np.identity(n) |
140 |
| - reflection_matrix[0,0] = -1.0 |
141 |
| - Z = np.matmul(Z, reflection_matrix) |
142 |
| - return({"P" : P, "Z" : Z, "Xtilde" : np.matmul(P, Z)}) |
143 |
| - |
144 | 117 | def create_zero_displacement_field(domain_image):
|
145 | 118 | field_array = np.zeros((*domain_image.shape, domain_image.dimension))
|
146 | 119 | field = ants.from_numpy(field_array, origin=domain_image.origin,
|
@@ -191,7 +164,7 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
|
191 | 164 | M = x11 * (1.0 - regularization) + regularization * y_prior
|
192 | 165 | Minv = np.linalg.lstsq(M, y, rcond=None)[0]
|
193 | 166 |
|
194 |
| - p = polar_decomposition(Minv[0:dimensionality, 0:dimensionality].T) |
| 167 | + p = ants.polar_decomposition(Minv[0:dimensionality, 0:dimensionality].T) |
195 | 168 | A = p['Xtilde']
|
196 | 169 | translation = Minv[dimensionality,:] + center_moving - center_fixed
|
197 | 170 |
|
@@ -296,7 +269,7 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
|
296 | 269 | updated_fixed_points[j,:] = total_field_xfrm.apply_to_point(tuple(fixed_points[j,:]))
|
297 | 270 |
|
298 | 271 | error_values.append(np.mean(np.sqrt(np.sum(np.square(updated_fixed_points - moving_points), axis=1, keepdims=True))))
|
299 |
| - convergence_value = convergence_monitoring(error_values) |
| 272 | + convergence_value = ants.convergence_monitoring(error_values) |
300 | 273 | if verbose:
|
301 | 274 | end_time = time.time()
|
302 | 275 | diff_time = end_time - start_time
|
@@ -395,7 +368,7 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
|
395 | 368 | updated_moving_points[j,:] = total_field_moving_to_middle_xfrm.apply_to_point(tuple(moving_points[j,:]))
|
396 | 369 |
|
397 | 370 | error_values.append(np.mean(np.sqrt(np.sum(np.square(updated_fixed_points - updated_moving_points), axis=1, keepdims=True))))
|
398 |
| - convergence_value = convergence_monitoring(error_values) |
| 371 | + convergence_value = ants.convergence_monitoring(error_values) |
399 | 372 | if verbose:
|
400 | 373 | end_time = time.time()
|
401 | 374 | diff_time = end_time - start_time
|
@@ -512,7 +485,7 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
|
512 | 485 | has_components=True)
|
513 | 486 |
|
514 | 487 | error_values.append(average_error)
|
515 |
| - convergence_value = convergence_monitoring(error_values) |
| 488 | + convergence_value = ants.convergence_monitoring(error_values) |
516 | 489 | if verbose:
|
517 | 490 | end_time = time.time()
|
518 | 491 | diff_time = end_time - start_time
|
@@ -816,7 +789,7 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
|
816 | 789 | has_components=True)
|
817 | 790 |
|
818 | 791 | error_values.append(average_error)
|
819 |
| - convergence_value = convergence_monitoring(error_values) |
| 792 | + convergence_value = ants.convergence_monitoring(error_values) |
820 | 793 | if verbose:
|
821 | 794 | end_time = time.time()
|
822 | 795 | diff_time = end_time - start_time
|
|
0 commit comments