Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fsleyes
fsleyes-widgets
Commits
69388f3d
Commit
69388f3d
authored
Oct 08, 2018
by
Paul McCarthy
🚵
Browse files
Merge branch 'test/image_test' into 'master'
Test/image test See merge request fsl/fsleyes/widgets!25
parents
30f29e89
8d9c9305
Changes
4
Show whitespace changes
Inline
Side-by-side
CHANGELOG.rst
View file @
69388f3d
...
...
@@ -2,6 +2,17 @@ This document contains the ``fsleyes-widgets`` release history in reverse
chronological order.
0.6.5 (Monday October 8th 2018)
-------------------------------
Changed
^^^^^^^
* Made some tests more lenient due to tiny cross-platform differences..
0.6.4 (Friday October 5th 2018)
-------------------------------
...
...
tests/__init__.py
View file @
69388f3d
...
...
@@ -19,36 +19,46 @@ import wx
GTK
=
any
([
'gtk'
in
p
.
lower
()
for
p
in
wx
.
PlatformInfo
])
def
compare_images
(
img1
,
img
2
,
threshold
):
"""Compares two images using the
euclidean distance in RGB space
between pixels
. Returns a tuple containing:
def
compare_images
(
arr1
,
arr
2
,
threshold
):
"""Compares two images using the
normalised difference of arr1 with respect
to arr2
. Returns a tuple containing:
- A boolean value indicating whether the test passed (the
image
s
were the same
).
- A boolean value indicating whether the test passed (the
difference wa
s
less than or equal to the threshold
).
- The
sum of the
normalised
RGB dista
nce between
all pixels
.
- The normalised
differe
nce between
the two.
.
"""
# Discard alpha values
img
1
=
img
1
[:,
:,
:
3
]
img
2
=
img
2
[:,
:,
:
3
]
arr
1
=
arr
1
[:,
:,
:
3
]
arr
2
=
arr
2
[:,
:,
:
3
]
if
img
1
.
shape
!=
img
2
.
shape
:
if
arr
1
.
shape
!=
arr
2
.
shape
:
return
False
,
0
finite1
=
np
.
isfinite
(
arr1
)
finite2
=
np
.
isfinite
(
arr2
)
flat1
=
img1
.
reshape
(
-
1
,
3
)
flat2
=
img2
.
reshape
(
-
1
,
3
)
if
not
np
.
all
(
finite1
==
finite2
):
return
1
dist
=
np
.
sqrt
(
np
.
sum
((
flat1
-
flat2
)
**
2
,
axis
=
1
))
dist
=
dist
.
reshape
(
img1
.
shape
[:
2
])
dist
=
dist
/
np
.
sqrt
(
3
*
255
*
255
)
a2zero
=
arr2
==
0
nzarr1
=
arr1
[
finite1
&
~
a2zero
]
nzarr2
=
arr2
[
finite1
&
~
a2zero
]
zarr1
=
arr1
[
finite1
&
a2zero
]
zarr2
=
arr2
[
finite1
&
a2zero
]
ttlDiff
=
np
.
sum
(
dist
)
if
nzarr2
.
size
>
0
:
zdenom
=
abs
(
nzarr2
.
mean
())
else
:
zdenom
=
1
passed
=
ttlDiff
<=
threshold
normdiff
=
np
.
zeros
(
arr1
.
shape
)
normdiff
[
finite1
&
~
a2zero
]
=
np
.
abs
((
nzarr2
-
nzarr1
)
/
nzarr2
)
normdiff
[
finite1
&
a2zero
]
=
np
.
abs
((
zarr2
-
zarr1
)
/
zdenom
)
return
passed
,
ttlDiff
if
normdiff
.
size
>
0
:
result
=
normdiff
.
mean
()
return
result
<=
threshold
,
result
else
:
return
True
,
0
def
run_with_wx
(
func
,
*
args
,
**
kwargs
):
...
...
tests/test_colourbarbitmap.py
View file @
69388f3d
...
...
@@ -27,7 +27,7 @@ def _compare(bmp, fname):
fname
=
op
.
join
(
datadir
,
fname
)
benchmark
=
mplimg
.
imread
(
fname
)
*
255
result
=
compare_images
(
bmp
,
benchmark
,
1
)
result
=
compare_images
(
bmp
,
benchmark
,
0.05
)
if
not
result
[
0
]:
print
(
result
)
...
...
tests/test_textbitmap.py
View file @
69388f3d
...
...
@@ -40,4 +40,4 @@ def test_textbitmap():
fname
=
op
.
join
(
datadir
,
fname
)
benchmark
=
mplimg
.
imread
(
fname
)
*
255
assert
compare_images
(
bmp
,
benchmark
,
1
)[
0
]
assert
compare_images
(
bmp
,
benchmark
,
0.05
)[
0
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment