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
5903a6fc
Commit
5903a6fc
authored
13 years ago
by
Richard Torenvliet
Browse files
Options
Downloads
Patches
Plain Diff
Made get_normalized_letter in NormalizedImage.py
parent
60a05ec2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/GrayscaleImage.py
+6
-1
6 additions, 1 deletion
src/GrayscaleImage.py
src/LocalBinaryPatternizer.py
+2
-2
2 additions, 2 deletions
src/LocalBinaryPatternizer.py
src/NormalizedImage.py
+12
-16
12 additions, 16 deletions
src/NormalizedImage.py
src/combined_test.py
+34
-5
34 additions, 5 deletions
src/combined_test.py
with
54 additions
and
24 deletions
src/GrayscaleImage.py
+
6
−
1
View file @
5903a6fc
from
pylab
import
imshow
,
imread
,
show
from
scipy.misc
import
imresize
class
GrayscaleImage
:
...
...
@@ -38,6 +39,10 @@ class GrayscaleImage:
imshow
(
self
.
data
,
cmap
=
"
gray
"
)
show
()
# size is of type float
def
resize
(
self
,
size
):
self
.
data
=
imresize
(
self
.
data
,
size
)
def
get_shape
(
self
):
return
self
.
data
.
shape
shape
=
property
(
get_shape
)
...
...
@@ -51,4 +56,4 @@ class GrayscaleImage:
height
=
property
(
get_height
)
def
in_bounds
(
self
,
y
,
x
):
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
\ No newline at end of file
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
This diff is collapsed.
Click to expand it.
src/LocalBinaryPatternizer.py
+
2
−
2
View file @
5903a6fc
from
numpy
import
zeros
,
byte
class
LocalBinaryPatternizer
:
def
__init__
(
self
,
image
,
cell_size
=
16
):
self
.
cell_size
=
cell_size
self
.
image
=
image
...
...
@@ -25,4 +25,4 @@ class LocalBinaryPatternizer:
return
self
.
features
def
is_pixel_darker
(
self
,
y
,
x
,
value
):
return
self
.
image
.
in_bounds
(
y
,
x
)
and
self
.
image
[
y
,
x
]
>
value
\ No newline at end of file
return
self
.
image
.
in_bounds
(
y
,
x
)
and
self
.
image
[
y
,
x
]
>
value
This diff is collapsed.
Click to expand it.
src/NormalizedImage.py
+
12
−
16
View file @
5903a6fc
from
PIL
import
Image
from
copy
import
deepcopy
class
NormalizedImage
:
DEFAULT_SIZE
=
(
100
,
200
)
def
__init__
(
self
,
image
,
size
):
self
.
letter
=
image
if
size
:
self
.
size
=
size
else
:
self
.
size
=
self
.
DEFAULT_SIZE
self
.
add_padding
()
self
.
resize
()
DEFAULT_SIZE
=
100.0
def
__init__
(
self
,
image
,
size
=
DEFAULT_SIZE
):
self
.
source_image
=
image
self
.
size
=
size
def
add_padding
(
self
):
pass
def
resize
(
self
):
return
self
.
letter
.
resize
(
self
.
size
,
Image
.
NEAREST
)
# 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
This diff is collapsed.
Click to expand it.
src/combined_test.py
+
34
−
5
View file @
5903a6fc
...
...
@@ -2,21 +2,50 @@ from GrayscaleImage import GrayscaleImage
from
LocalBinaryPatternizer
import
LocalBinaryPatternizer
from
LetterCropper
import
LetterCropper
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
,
axis
from
NormalizedImage
import
NormalizedImage
# 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
# Image is now an instance of class GrayscaleImage
# GrayscaleImage has functions like resize, crop etc.
image
=
GrayscaleImage
(
"
../images/test.png
"
)
cropper
=
LetterCropper
(
image
)
# Crops image; param threshold is optional: LetterCropper(image, threshold=0.9)
# image: GrayscaleImage, threshold: float
cropper
=
LetterCropper
(
image
,
0.9
)
cropped_letter
=
cropper
.
get_cropped_letter
()
lbp
=
LocalBinaryPatternizer
(
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
()
# Difference is noticable
print
resized
.
shape
lbp
=
LocalBinaryPatternizer
(
resized
)
feature_vector
=
lbp
.
create_features_vector
()
feature_vector
/=
255
# Prepare for displaying -> 0 - 255 -> 0 - 1
subplot
(
1
2
1
)
subplot
(
1
4
1
)
imshow
(
image
.
data
,
cmap
=
'
gray
'
)
subplot
(
122
)
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
()
\ No newline at end of file
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