Skip to content
Snippets Groups Projects
Commit 442475c6 authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Implements more tolerant tests based on image distances

parent aa03ba73
No related branches found
No related tags found
1 merge request!6Resolve "In painting has different output based on computer OS"
Pipeline #41680 failed
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
......@@ -28,6 +28,59 @@ def resource_path(relative_path, package="bob.ip.stereo"):
return resource_filename(package, relative_path)
def sum_of_squared_absolute_difference(array1, array2):
"""Sum the squared absolute difference between the input arrays.
"""
return np.sum((np.abs(array1.astype(np.float64)) - np.abs(array2.astype(np.float64))) ** 2)
def euclidian_distance(array1, array2):
"""Euclidian distance between the 2 input arrays (2 norm of the difference)
"""
return np.sqrt(np.sum(np.square(array1.astype(np.float64) - array2.astype(np.float64))))
def manhattan_distance(array1, array2):
"""Manhattan (or city block) distance between 2 inputs
"""
return np.sum(np.abs(array1.astype(np.float64) - array2.astype(np.float64)))
def canberra_distance(array1, array2):
"""Camberra distance between the 2 inputs
"""
return np.sum(
np.abs(array1.astype(np.float64) - array2.astype(np.float64))
/ (np.abs(array1.astype(np.float64)) + np.abs(array2.astype(np.float64)))
)
def is_close_enough(image1, image2):
"""Checks if the 2 inputs are close enough to pass the test, using different metrics.
The test is considered passed if the difference between the inputs is not more than the a small value for each pixel.
Eg: the first test is considered passed if "distance(image1, image2) < distance(image1, image1 + 2)"
The images are expected to be in unsigned int format (so positive).
"""
assert image1.shape == image2.shape
nb_elements = np.prod(image1.shape)
return (
sum_of_squared_absolute_difference(image1, image2) < 2 * nb_elements
and euclidian_distance(image1, image2) < 4 * nb_elements
and manhattan_distance(image1, image2) < 2 * nb_elements
and canberra_distance(image1, image2) < 2 * nb_elements / (np.mean(image1) + np.mean(image2))
)
def test_stereo_mapping_and_project():
"""
Test that an image projected onto the left camera of a camera pair is close
......@@ -45,7 +98,7 @@ def test_stereo_mapping_and_project():
nir_right_stereo = load_camera_config(resource_path("config/idiap_face_calibration.json"), "nir_right")
color = load_camera_config(resource_path("config/idiap_face_calibration.json"), "color")
camera_pair = CameraPair(nir_left_stereo, nir_right_stereo)
stereo_parameters = StereoParameters()
stereo_parameters.erode = True # remove small features
stereo_parameters.inpaint = True # fill holes
......@@ -63,5 +116,18 @@ def test_stereo_mapping_and_project():
assert groundtruth_color_image.shape == projected_image.shape
assert groundtruth_map_3d.shape == map_3d.shape
assert np.allclose(groundtruth_color_image, projected_image)
assert np.allclose(groundtruth_map_3d, map_3d)
# assert np.allclose(groundtruth_color_image, projected_image)
# assert np.allclose(groundtruth_map_3d, map_3d)
print("ssad", sum_of_squared_absolute_difference(groundtruth_color_image, projected_image))
print("n2", euclidian_distance(groundtruth_color_image, projected_image))
print("manhattan", manhattan_distance(groundtruth_color_image, projected_image))
print("canberra", canberra_distance(groundtruth_color_image, projected_image))
print("ssad", sum_of_squared_absolute_difference(groundtruth_map_3d, map_3d))
print("n2", euclidian_distance(groundtruth_map_3d, map_3d))
print("manhattan", manhattan_distance(groundtruth_map_3d, map_3d))
print("canberra", canberra_distance(groundtruth_map_3d, map_3d))
assert is_close_enough(groundtruth_color_image, projected_image)
assert is_close_enough(groundtruth_map_3d, map_3d)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment