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
44ce5bcc
Commit
44ce5bcc
authored
Nov 20, 2011
by
Gijs van der Voort
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alle regels kleiner of gelijk aan 80 gemaakt voor mr. Kroes
Imports opgefirst
parent
1fddc05d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
32 deletions
+28
-32
src/GrayscaleImage.py
src/GrayscaleImage.py
+1
-1
src/LetterCropper.py
src/LetterCropper.py
+22
-25
src/LetterCropperTest.py
src/LetterCropperTest.py
+5
-6
No files found.
src/GrayscaleImage.py
View file @
44ce5bcc
from
pylab
import
*
from
pylab
import
imshow
,
imread
,
show
class
GrayscaleImage
:
class
GrayscaleImage
:
...
...
src/LetterCropper.py
View file @
44ce5bcc
from
pylab
import
*
from
Rectangle
import
Rectangle
class
LetterCropper
:
class
LetterCropper
:
THRESHOLD
=
0.5
def
__init__
(
self
,
image
,
threshold
=
0.9
):
self
.
set_image
(
image
)
def
__init__
(
self
,
image_path
):
self
.
set_threshold
(
threshold
)
self
.
set_image
(
image_path
)
def
set_image
(
self
,
image
):
self
.
image
=
image
def
set_
image
(
self
,
image_path
):
def
set_
threshold
(
self
,
threshold
):
self
.
source_image
=
imread
(
image_path
)
self
.
threshold
=
threshold
def
get_cropped_letter
(
self
):
def
get_cropped_letter
(
self
):
self
.
convert_image_to_grayscale
()
self
.
determine_letter_bounds
()
self
.
determine_letter_bounds
()
self
.
crop_image
()
self
.
image
.
crop
(
self
.
letter_bounds
)
return
self
.
cropped_letter
return
self
.
image
def
convert_image_to_grayscale
(
self
):
self
.
cropped_letter
=
self
.
source_image
.
sum
(
axis
=
2
)
/
3
def
determine_letter_bounds
(
self
):
def
determine_letter_bounds
(
self
):
image_width
=
len
(
self
.
cropped_letter
[
0
])
image_height
=
len
(
self
.
cropped_letter
)
min_x
=
image_
width
min_x
=
self
.
image
.
width
max_x
=
0
max_x
=
0
min_y
=
image_
height
min_y
=
self
.
image
.
height
max_y
=
0
max_y
=
0
for
y
in
xrange
(
image_
height
):
for
y
in
xrange
(
self
.
image
.
height
):
for
x
in
xrange
(
image_
width
):
for
x
in
xrange
(
self
.
image
.
width
):
if
self
.
cropped_letter
[
y
,
x
]
<
self
.
THRESHOLD
:
if
self
.
image
[
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
self
.
letter_bounds
=
(
min_x
,
min_y
,
max_x
,
max_y
)
self
.
letter_bounds
=
Rectangle
(
min_x
,
def
crop_image
(
self
):
min_y
,
self
.
cropped_letter
=
self
.
cropped_letter
[
self
.
letter_bounds
[
1
]
:
self
.
letter_bounds
[
3
],
max_x
-
min_x
,
self
.
letter_bounds
[
0
]
:
self
.
letter_bounds
[
2
]]
max_y
-
min_y
)
src/LetterCropperTest.py
View file @
44ce5bcc
from
pylab
import
*
from
LetterCropper
import
LetterCropper
from
LetterCropper
import
LetterCropper
from
GrayscaleImage
import
GrayscaleImage
letter_cropper
=
LetterCropper
(
"../images/test.png"
)
image
=
GrayscaleImage
(
"../images/test.png"
)
cropped_letter
=
letter_cropper
.
get_cropped_letter
()
imshow
(
cropped_letter
,
cmap
=
"gray"
)
cropper
=
LetterCropper
(
image
)
show
()
cropped_letter
=
cropper
.
get_cropped_letter
()
cropped_letter
.
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