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
9719a9ad
Commit
9719a9ad
authored
Nov 25, 2011
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LocalBinaryPatternizer now creates histograms for all the cells in a 2d
array, but returns it as a 1d array of histograms
parent
60a05ec2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
+42
-24
src/LocalBinaryPatternizer.py
src/LocalBinaryPatternizer.py
+38
-13
src/LocalBinaryPatternizerTest.py
src/LocalBinaryPatternizerTest.py
+4
-11
No files found.
src/LocalBinaryPatternizer.py
View file @
9719a9ad
from
Histogram
import
Histogram
from
numpy
import
zeros
,
byte
from
numpy
import
zeros
,
byte
from
math
import
ceil
class
LocalBinaryPatternizer
:
class
LocalBinaryPatternizer
:
def
__init__
(
self
,
image
,
cell_size
=
16
):
def
__init__
(
self
,
image
,
cell_size
=
16
):
self
.
cell_size
=
cell_size
self
.
cell_size
=
cell_size
self
.
image
=
image
self
.
image
=
image
self
.
features
=
zeros
(
self
.
image
.
shape
)
self
.
setup_histograms
()
def
setup_histograms
(
self
):
cells_in_width
=
int
(
ceil
(
self
.
image
.
width
/
float
(
self
.
cell_size
)))
cells_in_height
=
int
(
ceil
(
self
.
image
.
height
/
float
(
self
.
cell_size
)))
self
.
features
=
[]
for
i
in
xrange
(
cells_in_height
):
self
.
features
.
append
([])
for
j
in
xrange
(
cells_in_width
):
self
.
features
[
i
].
append
(
Histogram
(
256
,
0
,
256
))
def
create_features_vector
(
self
):
def
create_features_vector
(
self
):
''' Walk around the pixels in clokwise order, shifting 1 bit less
''' Walk around the pixels in clokwise order, shifting 1 bit less
at each neighbour starting at 7 in the top-left corner. This gives a
at each neighbour starting at 7 in the top-left corner. This gives a
8-bit feature number of a pixel'''
8-bit feature number of a pixel'''
for
y
,
x
,
value
in
self
.
image
:
for
y
,
x
,
value
in
self
.
image
:
self
.
features
[
y
,
x
]
=
\
(
self
.
is_pixel_darker
(
y
-
1
,
x
-
1
,
value
)
<<
7
)
\
pattern
=
(
self
.
is_pixel_darker
(
y
-
1
,
x
-
1
,
value
)
<<
7
)
\
|
(
self
.
is_pixel_darker
(
y
-
1
,
x
,
value
)
<<
6
)
\
|
(
self
.
is_pixel_darker
(
y
-
1
,
x
,
value
)
<<
6
)
\
|
(
self
.
is_pixel_darker
(
y
-
1
,
x
+
1
,
value
)
<<
5
)
\
|
(
self
.
is_pixel_darker
(
y
-
1
,
x
+
1
,
value
)
<<
5
)
\
|
(
self
.
is_pixel_darker
(
y
,
x
+
1
,
value
)
<<
4
)
\
|
(
self
.
is_pixel_darker
(
y
,
x
+
1
,
value
)
<<
4
)
\
...
@@ -22,7 +35,19 @@ class LocalBinaryPatternizer:
...
@@ -22,7 +35,19 @@ class LocalBinaryPatternizer:
|
(
self
.
is_pixel_darker
(
y
+
1
,
x
-
1
,
value
)
<<
1
)
\
|
(
self
.
is_pixel_darker
(
y
+
1
,
x
-
1
,
value
)
<<
1
)
\
|
(
self
.
is_pixel_darker
(
y
,
x
-
1
,
value
)
<<
0
)
|
(
self
.
is_pixel_darker
(
y
,
x
-
1
,
value
)
<<
0
)
return
self
.
features
cy
,
cx
=
self
.
get_cell_index
(
y
,
x
)
self
.
features
[
cy
][
cx
].
add
(
pattern
)
return
self
.
get_features_as_array
()
def
is_pixel_darker
(
self
,
y
,
x
,
value
):
def
is_pixel_darker
(
self
,
y
,
x
,
value
):
return
self
.
image
.
in_bounds
(
y
,
x
)
and
self
.
image
[
y
,
x
]
>
value
return
self
.
image
.
in_bounds
(
y
,
x
)
and
self
.
image
[
y
,
x
]
>
value
def
get_cell_index
(
self
,
y
,
x
):
return
(
y
/
self
.
cell_size
,
x
/
self
.
cell_size
)
def
get_features_as_array
(
self
):
return
[
item
for
sublist
in
self
.
features
for
item
in
sublist
]
\ No newline at end of file
src/LocalBinaryPatternizerTest.py
View file @
9719a9ad
from
GrayscaleImage
import
GrayscaleImage
from
GrayscaleImage
import
GrayscaleImage
from
LocalBinaryPatternizer
import
LocalBinaryPatternizer
from
LocalBinaryPatternizer
import
LocalBinaryPatternizer
from
LetterCropper
import
LetterCropper
from
LetterCropper
import
LetterCropper
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
,
axis
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
,
axis
,
bar
from
numpy
import
arange
image
=
GrayscaleImage
(
"../images/test.png"
)
image
=
GrayscaleImage
(
"../images/test.png"
)
lbp
=
LocalBinaryPatternizer
(
image
)
lbp
=
LocalBinaryPatternizer
(
image
)
feature_vector
=
lbp
.
create_features_vector
()
histograms
=
lbp
.
create_features_vector
()
feature_vector
/=
255
# Prepare for displaying -> 0 - 255 -> 0 - 1
subplot
(
121
)
print
histograms
imshow
(
image
.
data
,
cmap
=
'gray'
)
\ No newline at end of file
subplot
(
122
)
imshow
(
feature_vector
,
cmap
=
'gray'
)
axis
(
'off'
)
show
()
\ No newline at end of file
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