Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bob.ip.stereo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.ip.stereo
Commits
442475c6
Commit
442475c6
authored
4 years ago
by
Vincent POLLET
Browse files
Options
Downloads
Patches
Plain Diff
Implements more tolerant tests based on image distances
parent
aa03ba73
No related branches found
No related tags found
1 merge request
!6
Resolve "In painting has different output based on computer OS"
Pipeline
#41680
failed
4 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/ip/stereo/test/test.py
+69
-3
69 additions, 3 deletions
bob/ip/stereo/test/test.py
with
69 additions
and
3 deletions
bob/ip/stereo/test/test.py
+
69
−
3
View file @
442475c6
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment