Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.vein
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
Package registry
Model registry
Operate
Environments
Terraform modules
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.bio.vein
Commits
8ef7a589
Commit
8ef7a589
authored
7 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
Use 'crop' instead of 'cropper'
parent
817f25cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!35
3DFV and multiple fixes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/vein/preprocessor/crop.py
+107
-0
107 additions, 0 deletions
bob/bio/vein/preprocessor/crop.py
with
107 additions
and
0 deletions
bob/bio/vein/preprocessor/crop.py
0 → 100644
+
107
−
0
View file @
8ef7a589
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
'''
Base utilities for pre-cropping images
'''
import
numpy
class
Cropper
(
object
):
"""
This is the base class for all croppers
It defines the minimum requirements for all derived cropper classes.
"""
def
__init__
(
self
):
pass
def
__call__
(
self
,
image
):
"""
Overwrite this method to implement your masking method
Parameters:
image (numpy.ndarray): A 2D numpy array of type ``uint8`` with the
input image
Returns:
numpy.ndarray: A 2D numpy array of the same type as the input, with
cropped rows and columns as per request
"""
raise
NotImplemented
(
'
You must implement the __call__ slot
'
)
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.
.. note::
Before choosing values, note you
'
re responsible for knowing what is the
orientation of images fed into this cropper.
Parameters:
top (:py:class:`int`, optional): Number of lines to suppress from the top
of the image. The top of the image corresponds to ``y = 0``.
bottom (:py:class:`int`, optional): Number of lines to suppress from the
bottom of the image. The bottom of the image corresponds to ``y =
height``.
left (:py:class:`int`, optional): Number of lines to suppress from the left
of the image. The left of the image corresponds to ``x = 0``.
right (:py:class:`int`, optional): Number of lines to suppress from the
right of the image. The right of the image corresponds to ``x = width``.
"""
def
__init__
(
self
,
top
=
0
,
bottom
=
0
,
left
=
0
,
right
=
0
):
self
.
top
=
top
self
.
bottom
=
bottom
self
.
left
=
left
self
.
right
=
right
def
__call__
(
self
,
image
):
"""
Returns a big mask
Parameters:
image (numpy.ndarray): A 2D numpy array of type ``uint8`` with the
input image
Returns:
numpy.ndarray: A 2D numpy array of type boolean with the caculated
mask. ``True`` values correspond to regions where the finger is
situated
"""
# this should work even if limits are zeros
h
,
w
=
image
.
shape
return
image
[
self
.
top
:
h
-
self
.
bottom
,
self
.
left
:
w
-
self
.
right
]
class
NoCrop
(
FixedCrop
):
"""
Convenience: same as FixedCrop()
"""
def
__init__
(
self
):
super
(
NoCrop
,
self
).
__init__
(
0
,
0
,
0
,
0
)
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