Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
licenseplates
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
licenseplates
Commits
e1a30839
Commit
e1a30839
authored
Nov 18, 2011
by
Gijs van der Voort
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Crop classes afgemaakt en test toegevoegd
parent
8acbc023
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
30 deletions
+50
-30
src/crop.py
src/crop.py
+39
-30
src/crop_test.py
src/crop_test.py
+11
-0
No files found.
src/crop.py
View file @
e1a30839
from
PIL
import
Image
from
PIL
import
Image
from
Pylab
import
*
from
pylab
import
*
from
LBP
import
domain_iterator
THRESHOLD
=
0.5
class
LetterCropper
:
im
=
Image
.
open
(
'../.jpg'
)
THRESHOLD
=
0.5
im
=
Image
.
convert
(
'L'
,
im
)
outer_bounds
=
get_outer_bounds
()
def
__init__
(
self
,
image_path
):
self
.
set_image
(
image_path
)
im
.
crop
(
outer_bounds
)
def
set_image
(
self
,
image_path
):
self
.
source_image
=
imread
(
image_path
)
imshow
(
im
)
def
get_cropped_letter
(
self
):
self
.
convert_image_to_grayscale
()
self
.
determine_letter_bounds
()
self
.
crop_image
()
return
self
.
cropped_letter
show
()
def
convert_image_to_grayscale
(
self
):
self
.
cropped_letter
=
self
.
source_image
.
sum
(
axis
=
2
)
/
3
def
get_outer_bound
():
def
determine_letter_bounds
(
self
):
min_x
=
len
(
im
[
0
])
image_width
=
len
(
self
.
cropped_letter
[
0
])
image_height
=
len
(
self
.
cropped_letter
)
min_x
=
image_width
max_x
=
0
max_x
=
0
min_y
=
len
(
im
)
min_y
=
image_height
max_y
=
0
max_y
=
0
for
y
in
xrange
(
len
(
im
)
):
for
y
in
xrange
(
image_height
):
for
x
in
xrange
(
len
(
im
[
0
])
):
for
x
in
xrange
(
image_width
):
if
im
[
y
,
x
]
>
THRESHOLD
:
if
self
.
cropped_letter
[
y
,
x
]
<
self
.
THRESHOLD
:
if
x
<
min_x
:
min_x
=
x
if
x
<
min_x
:
min_x
=
x
if
y
<
min_y
:
min_y
=
y
if
y
<
min_y
:
min_y
=
y
if
x
>
max_x
:
max_x
=
x
if
x
>
max_x
:
max_x
=
x
if
y
>
max_y
:
max_y
=
y
if
y
>
max_y
:
max_y
=
y
return
(
min_x
,
min_y
,
max_x
,
max_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
]]
src/crop_test.py
0 → 100644
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
()
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