Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
licenseplates
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
licenseplates
Commits
e1a30839
Commit
e1a30839
authored
13 years ago
by
Gijs van der Voort
Browse files
Options
Downloads
Patches
Plain Diff
Crop classes afgemaakt en test toegevoegd
parent
8acbc023
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
src/crop.py
+39
-30
39 additions, 30 deletions
src/crop.py
src/crop_test.py
+11
-0
11 additions, 0 deletions
src/crop_test.py
with
50 additions
and
30 deletions
src/crop.py
+
39
−
30
View file @
e1a30839
from
PIL
import
Image
from
Pylab
import
*
from
LBP
import
domain_iterator
from
pylab
import
*
THRESHOLD
=
0.5
class
LetterCropper
:
im
=
Image
.
open
(
'
../.jpg
'
)
im
=
Image
.
convert
(
'
L
'
,
im
)
THRESHOLD
=
0.5
outer_bounds
=
get_outer_bounds
()
im
.
crop
(
outer_bounds
)
imshow
(
im
)
show
()
def
get_outer_bound
():
min_x
=
len
(
im
[
0
])
max_x
=
0
min_y
=
len
(
im
)
max_y
=
0
for
y
in
xrange
(
len
(
im
)):
for
x
in
xrange
(
len
(
im
[
0
])):
if
im
[
y
,
x
]
>
THRESHOLD
:
if
x
<
min_x
:
min_x
=
x
if
y
<
min_y
:
min_y
=
y
if
x
>
max_x
:
max_x
=
x
if
y
>
max_y
:
max_y
=
y
return
(
min_x
,
min_y
,
max_x
,
max_y
)
def
__init__
(
self
,
image_path
):
self
.
set_image
(
image_path
)
def
set_image
(
self
,
image_path
):
self
.
source_image
=
imread
(
image_path
)
def
get_cropped_letter
(
self
):
self
.
convert_image_to_grayscale
()
self
.
determine_letter_bounds
()
self
.
crop_image
()
return
self
.
cropped_letter
def
convert_image_to_grayscale
(
self
):
self
.
cropped_letter
=
self
.
source_image
.
sum
(
axis
=
2
)
/
3
def
determine_letter_bounds
(
self
):
image_width
=
len
(
self
.
cropped_letter
[
0
])
image_height
=
len
(
self
.
cropped_letter
)
min_x
=
image_width
max_x
=
0
min_y
=
image_height
max_y
=
0
for
y
in
xrange
(
image_height
):
for
x
in
xrange
(
image_width
):
if
self
.
cropped_letter
[
y
,
x
]
<
self
.
THRESHOLD
:
if
x
<
min_x
:
min_x
=
x
if
y
<
min_y
:
min_y
=
y
if
x
>
max_x
:
max_x
=
x
if
y
>
max_y
:
max_y
=
y
self
.
letter_bounds
=
(
min_x
,
min_y
,
max_x
,
max_y
)
def
crop_image
(
self
):
self
.
cropped_letter
=
self
.
cropped_letter
[
self
.
letter_bounds
[
1
]
:
self
.
letter_bounds
[
3
],
self
.
letter_bounds
[
0
]
:
self
.
letter_bounds
[
2
]]
This diff is collapsed.
Click to expand it.
src/crop_test.py
0 → 100644
+
11
−
0
View file @
e1a30839
from
pylab
import
*
from
crop
import
LetterCropper
letter_cropper
=
LetterCropper
(
"
../images/test.png
"
)
cropped_letter
=
letter_cropper
.
get_cropped_letter
()
imshow
(
cropped_letter
,
cmap
=
"
gray
"
)
show
()
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