Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.bio.vein
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.bio.vein
Commits
19e4980d
Commit
19e4980d
authored
Jul 07, 2017
by
André Anjos
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test cropping with annotated images
parent
d3f2e266
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
bob/bio/vein/preprocessor/crop.py
bob/bio/vein/preprocessor/crop.py
+19
-2
bob/bio/vein/tests/test.py
bob/bio/vein/tests/test.py
+20
-0
No files found.
bob/bio/vein/preprocessor/crop.py
View file @
19e4980d
...
...
@@ -43,7 +43,9 @@ class FixedCrop(Cropper):
"""Implements cropping using a fixed suppression of border pixels
The defaults supress no lines from the image and returns an image like the
original.
original. If an :py:class:`..database.AnnotatedArray` is passed, then we also
check for its ``.metadata['roi']`` component and correct it so that annotated
RoI points are consistent on the cropped image.
.. note::
...
...
@@ -97,7 +99,22 @@ class FixedCrop(Cropper):
# this should work even if limits are zeros
h
,
w
=
image
.
shape
return
image
[
self
.
top
:
h
-
self
.
bottom
,
self
.
left
:
w
-
self
.
right
]
retval
=
image
[
self
.
top
:
h
-
self
.
bottom
,
self
.
left
:
w
-
self
.
right
]
if
hasattr
(
retval
,
'metadata'
)
and
'roi'
in
retval
.
metadata
:
# adjust roi points to new cropping
retval
=
retval
.
copy
()
#don't override original
h
,
w
=
retval
.
shape
points
=
[]
for
y
,
x
in
retval
.
metadata
[
'roi'
]:
y
=
max
(
y
-
self
.
top
,
0
)
#adjust
y
=
min
(
y
,
h
-
1
)
#verify it is not over the limits
x
=
max
(
x
-
self
.
left
,
0
)
#adjust
x
=
min
(
x
,
w
-
1
)
#verify it is not over the limits
points
.
append
((
y
,
x
))
retval
.
metadata
[
'roi'
]
=
points
return
retval
class
NoCrop
(
FixedCrop
):
...
...
bob/bio/vein/tests/test.py
View file @
19e4980d
...
...
@@ -51,6 +51,26 @@ def test_cropping():
nose
.
tools
.
eq_
(
cropped
.
shape
,
(
shape
[
0
]
-
(
top
+
bottom
),
shape
[
1
]
-
(
left
+
right
)))
nose
.
tools
.
eq_
((
test_image
[
top
:
-
bottom
,
left
:
-
right
]
-
cropped
).
sum
(),
0
)
# tests metadata survives after cropping (and it is corrected)
from
..database
import
AnnotatedArray
annotations
=
[
(
top
-
2
,
left
+
2
),
#slightly above and to the right
(
top
+
3
,
shape
[
1
]
-
(
right
+
1
)
+
3
),
#slightly down and to the right
(
shape
[
0
]
-
(
bottom
+
1
)
+
4
,
shape
[
1
]
-
(
right
+
1
)
-
2
),
(
shape
[
0
]
-
(
bottom
+
1
)
+
1
,
left
),
]
annotated_image
=
AnnotatedArray
(
test_image
,
metadata
=
dict
(
roi
=
annotations
))
assert
hasattr
(
annotated_image
,
'metadata'
)
cropped
=
fixed_crop
(
annotated_image
)
assert
hasattr
(
cropped
,
'metadata'
)
import
ipdb
;
ipdb
.
set_trace
()
assert
numpy
.
allclose
(
cropped
.
metadata
[
'roi'
],
[
(
0
,
2
),
(
3
,
cropped
.
shape
[
1
]
-
1
),
(
cropped
.
shape
[
0
]
-
1
,
4
),
(
cropped
.
shape
[
0
]
-
1
,
0
),
])
def
test_masking
():
...
...
Write
Preview
Markdown
is supported
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