Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions ants/registration/fit_bspline_displacement_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def fit_bspline_displacement_field(displacement_field=None,
if displacement_origins is not None:
if displacement_weights is not None and (len(displacement_weights) != displacement_origins.shape[0]):
raise ValueError("Length of displacement weights must match the number of displacement points.")
else:
displacement_weights = np.ones(displacement_origins.shape[0])

if isinstance(mesh_size, int) == False and len(mesh_size) != dimensionality:
raise ValueError("Incorrect specification for mesh_size.")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,20 @@ def test_bspline_field(self):
direction=np.array([[-1, 0], [0, -1]]),
number_of_fitting_levels=4, mesh_size=(1, 1))

def test_bspline_field_displacement_weights(self):
# two nearby points with opposite displacements: the field between them follows the heavier one
origins = np.array([[30.0, 32.0], [34.0, 32.0]])
deltas = np.array([[6.0, 0.0], [-6.0, 0.0]])
def u_x(weights):
field = ants.fit_bspline_displacement_field(
displacement_origins=origins, displacements=deltas, displacement_weights=weights,
origin=[0.0, 0.0], spacing=[1.0, 1.0], size=[64, 64], direction=np.eye(2),
number_of_fitting_levels=3, mesh_size=1, enforce_stationary_boundary=False)
return field.numpy()[32, 32, 0]
self.assertGreater(u_x(np.array([1.0, 1e-3])), 1)
self.assertLess(u_x(np.array([1e-3, 1.0])), -1)
self.assertAlmostEqual(u_x(None), u_x(np.ones(2)))

def test_quantile(self):
img = ants.image_read(ants.get_data('r16'))
ants.rank_intensity(img)
Expand Down
Loading