Commit b1defaa0 authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Merge branch 'debug_inpaint' into 2-in-painting-has-different-output-based-on-computer-os

parents 1d6ce6bf ecfe4a99
Pipeline #41690 passed with stage
in 5 minutes and 16 seconds
......@@ -5,7 +5,7 @@
Test Units
"""
# ==============================================================================
from bob.ip.stereo.stereo import stereo_match, reproject_image
from bob.ip.stereo.stereo import stereo_match, reproject_image, StereoParameters
from bob.ip.stereo.camera import load_camera_config, CameraPair
from bob.io.base import load
......@@ -28,6 +28,62 @@ 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) + 1.0))
)
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 on average.
Eg: the first test is considered passed if "distance(image1, image2) < distance(image1, image1 + epsilon)"
The images are expected to be in unsigned int format (so positive).
"""
assert image1.shape == image2.shape
nb_elements = np.prod(image1.shape)
epsilon = 0.5 # allowed average difference between image
return (
sum_of_squared_absolute_difference(image1, image2) < epsilon * nb_elements
and euclidian_distance(image1, image2) < (epsilon ** 2) * nb_elements
and manhattan_distance(image1, image2) < epsilon * nb_elements
and canberra_distance(image1, image2) < epsilon * 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
......@@ -46,8 +102,12 @@ def test_stereo_mapping_and_project():
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
# Create 3D image
map_3d = stereo_match(left_image, right_image, camera_pair)
map_3d = stereo_match(left_image, right_image, camera_pair, stereo_parameters)
# project color image on left camera (rectified)
projected_image = reproject_image(color_image, map_3d, color, camera_pair)
......@@ -59,5 +119,5 @@ 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 is_close_enough(groundtruth_color_image, projected_image)
assert is_close_enough(groundtruth_map_3d, map_3d)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment