Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add verbose and additional outputs. #416

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions ants/registration/landmark_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def fit_transform_to_paired_points( moving_points,
number_of_compositions=10,
composition_step_size=0.5,
sigma=0.0,
number_of_integration_points=2
number_of_integration_points=2,
verbose=False
):
"""
Estimate an optimal matrix transformation from paired points, potentially landmarks
Expand Down Expand Up @@ -79,6 +80,9 @@ def fit_transform_to_paired_points( moving_points,
number_of_integration_points : integer
Time-varying velocity field parameter.

verbose : bool
Print progress to the screen.

Returns
-------

Expand Down Expand Up @@ -238,6 +242,10 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
for j in range(updated_fixed_points.shape[0]):
updated_fixed_points[j,:] = total_field_xfrm.apply_to_point(tuple(fixed_points[j,:]))

if verbose:
error = np.mean(np.sqrt(np.sum(np.square(updated_fixed_points - moving_points), axis=1, keepdims=True)))
print("Composition " + str(i) + ": error = " + str(error))

return(total_field_xfrm)

elif transform_type == "syn":
Expand Down Expand Up @@ -314,12 +322,23 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
total_inverse_field_fixed_to_middle_xfrm = txio.transform_from_displacement_field(total_inverse_field_fixed_to_middle)
total_inverse_field_moving_to_middle_xfrm = txio.transform_from_displacement_field(total_inverse_field_moving_to_middle)

if verbose:
error = np.mean(np.sqrt(np.sum(np.square(updated_fixed_points - updated_moving_points), axis=1, keepdims=True)))
print("Composition " + str(i) + ": error = " + str(error))

xfrm_forward_list = [total_field_fixed_to_middle_xfrm, total_inverse_field_moving_to_middle_xfrm]
total_forward_xfrm = tx.compose_ants_transforms(xfrm_forward_list)
xfrm_inverse_list = [total_field_moving_to_middle_xfrm, total_inverse_field_fixed_to_middle_xfrm]
total_inverse_xfrm = tx.compose_ants_transforms(xfrm_inverse_list)

return([total_forward_xfrm, total_inverse_xfrm])
return_dict = {'forward_transform' : total_forward_xfrm,
'inverse_transform' : total_inverse_xfrm,
'fixed_to_middle_transform' : total_field_fixed_to_middle_xfrm,
'middle_to_fixed_transform' : total_inverse_field_fixed_to_middle_xfrm,
'moving_to_middle_transform' : total_field_moving_to_middle_xfrm,
'middle_to_moving_transform' : total_inverse_field_moving_to_middle_xfrm
}
return(return_dict)

elif transform_type == "tv" or transform_type == "time-varying":

Expand All @@ -339,6 +358,9 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
update_derivative_field = create_zero_velocity_field(domain_image, number_of_integration_points)
update_derivative_field_array = update_derivative_field.numpy()

if verbose:
print("Composition " + str(i))

for n in range(number_of_integration_points):

t = n / (number_of_integration_points - 1.0)
Expand All @@ -359,6 +381,10 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
else:
updated_moving_points[:] = moving_points

if verbose:
error = np.mean(np.sqrt(np.sum(np.square(updated_fixed_points - updated_moving_points), axis=1, keepdims=True)))
print(" Integration t = " + str(t) + ": error = " + str(error))

update_derivative_field_at_timepoint = fit_bspline_displacement_field(
displacement_origins=updated_fixed_points,
displacements=updated_moving_points - updated_fixed_points,
Expand Down Expand Up @@ -392,7 +418,13 @@ def create_zero_velocity_field(domain_image, number_of_time_points=2):
spacing=velocity_field.spacing, direction=velocity_field.direction,
has_components=True)

return(velocity_field)
forward_xfrm = txio.transform_from_displacement_field(integrate_velocity_field(velocity_field, 0.0, 1.0, 100))
inverse_xfrm = txio.transform_from_displacement_field(integrate_velocity_field(velocity_field, 1.0, 0.0, 100))

return_dict = {'forward_transform': forward_xfrm,
'inverse_transform': inverse_xfrm,
'velocity_field': velocity_field}
return(return_dict)

else:
raise ValueError("Unrecognized transform_type.")
Expand Down