Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
a9734938
Commit
a9734938
authored
5 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Create tests for patterns
parent
f097a2a0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
navipy/arenatools/patterns.py
+8
-8
8 additions, 8 deletions
navipy/arenatools/patterns.py
navipy/arenatools/test_pattern.py
+45
-0
45 additions, 0 deletions
navipy/arenatools/test_pattern.py
with
53 additions
and
8 deletions
navipy/arenatools/patterns.py
+
8
−
8
View file @
a9734938
...
...
@@ -32,7 +32,7 @@ the noise (default: random generated noise)
noise
=
np
.
random
.
randn
(
s
,
s
)
# calculate filter
fx
=
np
.
arange
(
s
/
2
)
+
1
fx
=
np
.
arange
(
s
/
2
)
+
1
# index from 0-s/2,s/2-0 -> middle highest index
fx
=
np
.
hstack
([
fx
,
fx
[
-
1
::
-
1
]])
fx
=
fx
[:,
np
.
newaxis
]
...
...
@@ -45,7 +45,7 @@ the noise (default: random generated noise)
f
=
f
**
(
-
beta
)
# apply filter in frequency domain
# calculate disrete furier transformations
fnoise
=
np
.
fft
.
ifft2
(
np
.
fft
.
fft2
(
noise
)
*
f
)
fnoise
=
np
.
fft
.
ifft2
(
np
.
fft
.
fft2
(
noise
)
*
f
)
# trim to image size
fnoise
=
fnoise
[:
img_size
[
0
],
:
img_size
[
1
]]
...
...
@@ -65,8 +65,8 @@ def gray2red(img):
img
=
img
[...,
np
.
newaxis
]
img
=
img
.
repeat
(
3
,
axis
=
2
)
maxval
=
np
.
max
(
img
)
img
[:,
:,
1
]
=
maxval
-
img
[:,
:,
0
]
img
[:,
:,
2
]
=
maxval
-
img
[:,
:,
0
]
img
[:,
:,
1
]
=
maxval
-
img
[:,
:,
0
]
img
[:,
:,
2
]
=
maxval
-
img
[:,
:,
0
]
img
[:,
:,
0
]
=
maxval
return
img
...
...
@@ -83,16 +83,16 @@ def norm_img(img):
return
img
.
astype
(
np
.
uint8
)
def
rectangular_pattern
(
width
,
length
,
beta
=
1.4
,
pixel_per_mm
=
1
):
def
rectangular_pattern
(
width
,
height
,
beta
=
1.4
,
pixel_per_mm
=
1
):
"""
generate a rectangular pattern
:param width: width of the pattern in mm
:param
length: length
of the pattern in mm
:param
height: height
of the pattern in mm
:param beta: beta coef for generating a 1/(f^beta) pattern
:param pixel_per_mm: number of pixel per mm
:returns: a rectangular random image
:rtype: np.ndarray
"""
corridor
=
np
.
array
([
width
,
leng
th
])
corridor_px
=
corridor
*
pixel_per_mm
# in px
corridor
=
np
.
array
([
height
,
wid
th
])
corridor_px
=
corridor
*
pixel_per_mm
# in px
return
generate_1overf_noise
(
corridor_px
,
beta
)
This diff is collapsed.
Click to expand it.
navipy/arenatools/test_pattern.py
0 → 100644
+
45
−
0
View file @
a9734938
import
unittest
import
numpy
as
np
import
navipy.arenatools.patterns
as
tobetested
# import matplotlib.pyplot as plt
class
TestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
width
=
201
self
.
height
=
100
self
.
beta
=
2
self
.
pixel_per_mm
=
2
self
.
image
=
tobetested
.
rectangular_pattern
(
self
.
width
,
self
.
height
,
self
.
beta
,
self
.
pixel_per_mm
)
def
test_rectangular_patter
(
self
):
"""
Chech the image dimension
"""
# Check image dimension
# * height
# * width
self
.
assertEqual
(
self
.
image
.
shape
[
0
],
self
.
height
*
self
.
pixel_per_mm
)
self
.
assertEqual
(
self
.
image
.
shape
[
1
],
self
.
width
*
self
.
pixel_per_mm
)
def
test_norm_img
(
self
):
"""
Check that normalised image span [0,255]
"""
im
=
np
.
random
.
rand
(
100
,
101
)
im
=
tobetested
.
norm_img
(
im
)
self
.
assertEqual
(
im
.
min
(),
0
)
self
.
assertEqual
(
im
.
max
(),
255
)
def
test_gray2red
(
self
):
"""
Check that green=blue, red == max
"""
red
=
tobetested
.
gray2red
(
self
.
image
.
copy
())
# The red channel should be equal to max
np
.
testing
.
assert_array_equal
(
red
[...,
0
],
self
.
image
.
max
())
# Green==Blue
np
.
testing
.
assert_array_equal
(
red
[...,
1
],
red
[...,
2
])
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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