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
d3bc209a
Commit
d3bc209a
authored
Dec 09, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added character comparison script that uses histogram intersection.
parent
c333da85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
src/Histogram.py
src/Histogram.py
+12
-0
src/test_compare.py
src/test_compare.py
+63
-0
No files found.
src/Histogram.py
View file @
d3bc209a
...
@@ -16,3 +16,15 @@ class Histogram:
...
@@ -16,3 +16,15 @@ class Histogram:
def
get_bin_index
(
self
,
number
):
def
get_bin_index
(
self
,
number
):
return
(
number
-
self
.
min
)
/
((
self
.
max
-
self
.
min
)
/
len
(
self
.
bins
))
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
)
src/test_compare.py
0 → 100755
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
()
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