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
d3bc209a
Commit
d3bc209a
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added character comparison script that uses histogram intersection.
parent
c333da85
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/Histogram.py
+12
-0
12 additions, 0 deletions
src/Histogram.py
src/test_compare.py
+63
-0
63 additions, 0 deletions
src/test_compare.py
with
75 additions
and
0 deletions
src/Histogram.py
+
12
−
0
View file @
d3bc209a
...
...
@@ -16,3 +16,15 @@ class Histogram:
def
get_bin_index
(
self
,
number
):
return
(
number
-
self
.
min
)
/
((
self
.
max
-
self
.
min
)
/
len
(
self
.
bins
))
def
intersect
(
self
,
other
):
h1
=
self
.
bins
h2
=
other
.
bins
match
=
0
# Add the minimum of each bin to the result
for
b
in
xrange
(
len
(
self
.
bins
)):
match
+=
min
(
h1
[
b
],
h2
[
b
])
# Normalize by dividing by the number of pixels
return
float
(
match
)
/
sum
(
h2
)
This diff is collapsed.
Click to expand it.
src/test_compare.py
0 → 100755
+
63
−
0
View file @
d3bc209a
#!/usr/bin/python
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
from
LocalBinaryPatternizer
import
LocalBinaryPatternizer
from
GrayscaleImage
import
GrayscaleImage
from
cPickle
import
load
from
numpy
import
zeros
,
resize
chars
=
load
(
file
(
'
chars
'
,
'
r
'
))[::
2
]
left
=
None
right
=
None
for
c
in
chars
:
if
c
.
value
==
'
8
'
:
if
left
==
None
:
left
=
c
.
image
elif
right
==
None
:
right
=
c
.
image
else
:
break
size
=
16
d
=
(
left
.
size
[
0
]
*
4
,
left
.
size
[
1
]
*
4
)
#GrayscaleImage.resize(left, d)
#GrayscaleImage.resize(right, d)
p1
=
LocalBinaryPatternizer
(
left
,
size
)
p1
.
create_features_vector
()
p1
=
p1
.
features
p2
=
LocalBinaryPatternizer
(
right
,
size
)
p2
.
create_features_vector
()
p2
=
p2
.
features
s
=
(
len
(
p1
),
len
(
p1
[
0
]))
match
=
zeros
(
left
.
shape
)
m
=
0
for
y
in
range
(
s
[
0
]):
for
x
in
range
(
s
[
1
]):
h1
=
p1
[
y
][
x
]
h2
=
p2
[
y
][
x
]
intersect
=
h1
.
intersect
(
h2
)
print
intersect
for
i
in
xrange
(
size
):
for
j
in
xrange
(
size
):
try
:
match
[
y
*
size
+
i
,
x
*
size
+
j
]
=
1
-
intersect
except
IndexError
:
pass
m
+=
intersect
print
'
Match: %d%%
'
%
int
(
m
/
(
s
[
0
]
*
s
[
1
])
*
100
)
subplot
(
311
)
imshow
(
left
.
data
,
cmap
=
'
gray
'
)
subplot
(
312
)
imshow
(
match
,
cmap
=
'
gray
'
)
subplot
(
313
)
imshow
(
right
.
data
,
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