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
c3c35032
Commit
c3c35032
authored
Dec 02, 2011
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
worked on letter cropper
parent
accab14c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
76 deletions
+51
-76
images/test10.png
images/test10.png
+0
-0
src/GaussianFilter.py
src/GaussianFilter.py
+6
-1
src/GrayscaleImage.py
src/GrayscaleImage.py
+7
-2
src/LetterCropper.py
src/LetterCropper.py
+2
-2
src/NormalizedCharacterImage.py
src/NormalizedCharacterImage.py
+31
-0
src/NormalizedImage.py
src/NormalizedImage.py
+0
-17
src/combined_test.py
src/combined_test.py
+5
-54
No files found.
images/test10.png
0 → 100644
View file @
c3c35032
1.04 KB
src/GaussianFilter.py
View file @
c3c35032
...
...
@@ -30,6 +30,11 @@ class GaussianFilter:
image
=
convolve1d
(
image
.
data
,
kernel
,
axis
=
0
,
mode
=
'nearest'
)
return
GrayscaleImage
(
None
,
convolve1d
(
image
,
kernel
,
axis
=
1
,
mode
=
'nearest'
))
def
filter
(
self
,
image
):
kernel
=
self
.
get_1d_gaussian_kernel
()
image
.
data
=
convolve1d
(
image
.
data
,
kernel
,
axis
=
0
,
mode
=
'nearest'
)
image
.
data
=
convolve1d
(
image
.
data
,
kernel
,
axis
=
1
,
mode
=
'nearest'
)
def
get_scale
(
self
):
return
self
.
scale
...
...
src/GrayscaleImage.py
View file @
c3c35032
from
pylab
import
imshow
,
imread
,
show
from
scipy.misc
import
imresize
from
matplotlib.pyplot
import
hist
class
GrayscaleImage
:
...
...
@@ -37,10 +38,14 @@ class GrayscaleImage:
def
show
(
self
):
imshow
(
self
.
data
,
cmap
=
"gray"
)
show
()
#
show()
# size is of type float
def
make_histogram
(
self
):
return
hist
(
self
.
data
)
# size is of type tuple of integers (DEFAULT = (50, 50))
def
resize
(
self
,
size
):
print
size
self
.
data
=
imresize
(
self
.
data
,
size
)
def
get_shape
(
self
):
...
...
src/LetterCropper.py
View file @
c3c35032
...
...
@@ -3,7 +3,7 @@ from Rectangle import Rectangle
class
LetterCropper
:
def
__init__
(
self
,
image
,
threshold
=
0.9
):
def
__init__
(
self
,
threshold
=
0.9
):
self
.
source_image
=
image
self
.
threshold
=
threshold
...
...
src/NormalizedCharacterImage.py
0 → 100644
View file @
c3c35032
from
copy
import
deepcopy
from
GrayscaleImage
import
GrayscaleImage
from
LetterCropper
import
LetterCropper
from
GaussianFilter
import
GaussianFilter
class
NormalizedCharacterImage
(
GrayscaleImage
):
def
__init__
(
self
,
image
,
size
=
(
60
,
40
),
blur
=
1.1
,
crop_threshold
=
0.9
):
GrayscaleImage
.
__init__
(
self
,
data
=
deepcopy
(
image
.
data
))
self
.
blur
=
blur
self
.
crop_threshold
=
crop_threshold
self
.
size
=
size
self
.
gausse_filter
()
self
.
increase_contrast
()
self
.
crop
()
self
.
resize
()
def
increase_contrast
(
self
):
self
.
data
-=
self
.
data
.
min
()
self
.
data
/=
self
.
data
.
max
()
def
gausse_filter
(
self
):
filter
=
GaussianFilter
(
1.1
)
filter
.
filter
(
self
)
def
crop
(
self
):
cropper
=
LetterCropper
(
self
,
0.9
)
self
.
data
=
cropper
.
get_cropped_letter
().
data
def
resize
(
self
):
self
.
resize
(
self
.
size
)
src/NormalizedImage.py
deleted
100644 → 0
View file @
accab14c
from
copy
import
deepcopy
class
NormalizedImage
:
DEFAULT_SIZE
=
100.0
def
__init__
(
self
,
image
,
size
=
DEFAULT_SIZE
):
self
.
source_image
=
image
self
.
size
=
size
def
add_padding
(
self
):
pass
# normalize img
def
get_normalized_letter
(
self
):
self
.
result_image
=
deepcopy
(
self
.
source_image
)
self
.
result_image
.
resize
(
self
.
size
/
self
.
source_image
.
height
)
return
self
.
result_image
src/combined_test.py
View file @
c3c35032
from
GrayscaleImage
import
GrayscaleImage
from
LocalBinaryPatternizer
import
LocalBinaryPatternizer
from
LetterCropper
import
LetterCropper
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
,
axis
from
NormalizedImage
import
NormalizedImage
from
GaussianFilter
import
GaussianFilter
from
NormalizedCharacterImage
import
NormalizedCharacterImage
# Comment added by Richard Torenvliet
# Steps in this test files are
# 1. crop image
# 2. resize to default hight (in future also to width)
# 3. preform LBP
# 4. construct feature vector
# 5. plot
# 3. plot
# Image is now an instance of class GrayscaleImage
# GrayscaleImage has functions like resize, crop etc.
image
=
GrayscaleImage
(
"../images/test9.png"
)
filter
=
GaussianFilter
(
1.4
)
image
=
filter
.
get_filtered_copy
(
image
)
# Crops image; param threshold is optional: LetterCropper(image, threshold=0.9)
# image: GrayscaleImage, threshold: float
cropper
=
LetterCropper
(
image
,
0.7
)
cropped_letter
=
cropper
.
get_cropped_letter
()
# Show difference in shape
print
cropped_letter
.
shape
# Resizes image; param size is optional: NormalizedImage(image, size=DEFAULT)
# image: GrayscaleImage, size: float
norm
=
NormalizedImage
(
cropped_letter
)
resized
=
norm
.
get_normalized_letter
()
print
resized
.
show
()
show
()
# Difference is noticable
print
resized
.
shape
lbp
=
LocalBinaryPatternizer
(
resized
)
feature_vector
=
lbp
.
create_features_vector
()
print
feature_vector
feature_vector
/=
255
# Prepare for displaying -> 0 - 255 -> 0 - 1
subplot
(
141
)
imshow
(
image
.
data
,
cmap
=
'gray'
)
subplot
(
142
)
imshow
(
cropped_letter
.
data
,
cmap
=
'gray'
)
subplot
(
143
)
imshow
(
resized
.
data
,
cmap
=
'gray'
)
subplot
(
144
)
imshow
(
feature_vector
,
cmap
=
'gray'
)
axis
(
'off'
)
show
()
image
=
GrayscaleImage
(
"../images/test10.png"
)
normalized_character_image
=
NormalizedCharacterImage
(
image
)
normalized_character_image
.
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