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
a1848059
Commit
a1848059
authored
Dec 02, 2011
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Plain Diff
Resolved conflicts.
parents
c3c35032
9b5b2543
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
83 deletions
+14
-83
src/GrayscaleImage.py
src/GrayscaleImage.py
+13
-3
src/LBP.py
src/LBP.py
+0
-74
src/LocalBinaryPatternizer.py
src/LocalBinaryPatternizer.py
+1
-6
No files found.
src/GrayscaleImage.py
View file @
a1848059
from
pylab
import
imshow
,
imread
,
show
from
pylab
import
imshow
,
imread
,
show
from
scipy.misc
import
imresize
from
scipy.misc
import
imresize
from
matplotlib.pyplot
import
hist
from
matplotlib.pyplot
import
hist
from
scipy.misc
import
imresize
,
imsave
class
GrayscaleImage
:
class
GrayscaleImage
:
def
__init__
(
self
,
image_path
=
None
,
data
=
None
):
def
__init__
(
self
,
image_path
=
None
,
data
=
None
):
if
image_path
!=
None
:
if
image_path
:
self
.
data
=
imread
(
image_path
)
self
.
data
=
imread
(
image_path
)
self
.
convert_to_grayscale
()
self
.
convert_to_grayscale
()
elif
data
!=
None
:
elif
data
:
self
.
data
=
data
self
.
data
=
data
def
__iter__
(
self
):
def
__iter__
(
self
):
...
@@ -30,7 +31,8 @@ class GrayscaleImage:
...
@@ -30,7 +31,8 @@ class GrayscaleImage:
return
self
.
data
[
position
]
return
self
.
data
[
position
]
def
convert_to_grayscale
(
self
):
def
convert_to_grayscale
(
self
):
self
.
data
=
self
.
data
.
sum
(
axis
=
2
)
/
3
if
len
(
self
.
data
.
shape
)
>
2
:
self
.
data
=
self
.
data
[:,:,:
3
].
sum
(
axis
=
2
)
/
3
def
crop
(
self
,
rectangle
):
def
crop
(
self
,
rectangle
):
self
.
data
=
self
.
data
[
rectangle
.
y
:
rectangle
.
y
+
rectangle
.
height
,
self
.
data
=
self
.
data
[
rectangle
.
y
:
rectangle
.
y
+
rectangle
.
height
,
...
@@ -46,19 +48,27 @@ class GrayscaleImage:
...
@@ -46,19 +48,27 @@ class GrayscaleImage:
# size is of type tuple of integers (DEFAULT = (50, 50))
# size is of type tuple of integers (DEFAULT = (50, 50))
def
resize
(
self
,
size
):
def
resize
(
self
,
size
):
print
size
print
size
def
resize
(
self
,
size
):
# size is of type float
self
.
data
=
imresize
(
self
.
data
,
size
)
self
.
data
=
imresize
(
self
.
data
,
size
)
def
get_shape
(
self
):
def
get_shape
(
self
):
return
self
.
data
.
shape
return
self
.
data
.
shape
shape
=
property
(
get_shape
)
shape
=
property
(
get_shape
)
def
get_width
(
self
):
def
get_width
(
self
):
return
self
.
get_shape
()[
1
]
return
self
.
get_shape
()[
1
]
width
=
property
(
get_width
)
width
=
property
(
get_width
)
def
get_height
(
self
):
def
get_height
(
self
):
return
self
.
get_shape
()[
0
]
return
self
.
get_shape
()[
0
]
height
=
property
(
get_height
)
height
=
property
(
get_height
)
def
in_bounds
(
self
,
y
,
x
):
def
in_bounds
(
self
,
y
,
x
):
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
def
save
(
self
,
path
):
imsave
(
path
,
self
.
data
)
src/LBP.py
deleted
100755 → 0
View file @
c3c35032
#!/usr/bin/python
import
Image
from
numpy
import
array
,
zeros
,
byte
from
matplotlib.pyplot
import
imshow
,
subplot
,
show
,
axis
# Divide the examined window to cells (e.g. 16x16 pixels for each cell).
# For each pixel in a cell, compare the pixel to each of its 8 neighbors
# (on its left-top, left-middle, left-bottom, right-top, etc.). Follow the
# pixels along a circle, i.e. clockwise or counter-clockwise.
# Where the center pixel's value is greater than the neighbor, write "1".
# Otherwise, write "0". This gives an 8-digit binary number (which is usually
# converted to decimal for convenience).
# Compute the histogram, over the cell, of the frequency of each "number"
# occurring (i.e., each combination of which pixels are smaller and which are
# greater than the center).
# Optionally normalize the histogram. Concatenate normalized histograms of all
# cells. This gives the feature vector for the window.
CELL_SIZE
=
16
def
domain_iterator
(
shape
):
"""Iterate over the pixels of an image."""
for
y
in
xrange
(
shape
[
0
]):
for
x
in
xrange
(
shape
[
1
]):
yield
y
,
x
image
=
array
(
Image
.
open
(
'../images/test.png'
).
convert
(
'L'
))
def
in_image
(
y
,
x
,
F
):
"""Check if given pixel coordinates are within the bounds of image F."""
return
0
<=
y
<
F
.
shape
[
0
]
and
0
<=
x
<
F
.
shape
[
1
]
def
features
(
image
):
"""Compare each pixel to each of its eight neigheach pixel to each of its
eight neighbours."""
features
=
zeros
(
image
.
shape
,
dtype
=
byte
)
def
cmp_pixels
(
y
,
x
,
p
):
"""Check if two pixels (y, x) and p are in the image, and if the value
at (y, x) is larger than the value at p."""
return
in_image
(
y
,
x
,
image
)
and
image
[
y
,
x
]
>
p
for
y
,
x
in
domain_iterator
(
features
.
shape
):
p
=
image
[
y
,
x
]
# Walk around the pixel in counter-clokwise order, shifting 1 bit less
# at each neighbour starting at 7 in the top-left corner. This gives a
# 8-bit feature number of a pixel
features
[
y
,
x
]
=
byte
(
cmp_pixels
(
y
-
1
,
x
-
1
,
p
))
<<
7
\
|
byte
(
cmp_pixels
(
y
-
1
,
x
,
p
))
<<
6
\
|
byte
(
cmp_pixels
(
y
-
1
,
x
+
1
,
p
))
<<
5
\
|
byte
(
cmp_pixels
(
y
,
x
+
1
,
p
))
<<
4
\
|
byte
(
cmp_pixels
(
y
+
1
,
x
+
1
,
p
))
<<
3
\
|
byte
(
cmp_pixels
(
y
+
1
,
x
,
p
))
<<
2
\
|
byte
(
cmp_pixels
(
y
+
1
,
x
-
1
,
p
))
<<
1
\
|
byte
(
cmp_pixels
(
y
,
x
-
1
,
p
))
return
features
def
feature_vectors
(
image
):
"""Create cell histograms of an image"""
F
=
features
(
image
)
V
=
feature_vectors
(
image
)
subplot
(
121
)
imshow
(
image
,
cmap
=
'gray'
)
subplot
(
122
)
imshow
(
V
,
cmap
=
'gray'
)
axis
(
'off'
)
show
()
src/LocalBinaryPatternizer.py
View file @
a1848059
...
@@ -9,7 +9,6 @@ class LocalBinaryPatternizer:
...
@@ -9,7 +9,6 @@ class LocalBinaryPatternizer:
self
.
image
=
image
self
.
image
=
image
self
.
setup_histograms
()
self
.
setup_histograms
()
def
setup_histograms
(
self
):
def
setup_histograms
(
self
):
cells_in_width
=
int
(
ceil
(
self
.
image
.
width
/
float
(
self
.
cell_size
)))
cells_in_width
=
int
(
ceil
(
self
.
image
.
width
/
float
(
self
.
cell_size
)))
cells_in_height
=
int
(
ceil
(
self
.
image
.
height
/
float
(
self
.
cell_size
)))
cells_in_height
=
int
(
ceil
(
self
.
image
.
height
/
float
(
self
.
cell_size
)))
...
@@ -19,7 +18,6 @@ class LocalBinaryPatternizer:
...
@@ -19,7 +18,6 @@ class LocalBinaryPatternizer:
for
j
in
xrange
(
cells_in_width
):
for
j
in
xrange
(
cells_in_width
):
self
.
features
[
i
].
append
(
Histogram
(
256
,
0
,
256
))
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
...
@@ -40,14 +38,11 @@ class LocalBinaryPatternizer:
...
@@ -40,14 +38,11 @@ class LocalBinaryPatternizer:
return
self
.
get_features_as_array
()
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
):
def
get_cell_index
(
self
,
y
,
x
):
return
(
y
/
self
.
cell_size
,
x
/
self
.
cell_size
)
return
(
y
/
self
.
cell_size
,
x
/
self
.
cell_size
)
def
get_features_as_array
(
self
):
def
get_features_as_array
(
self
):
return
[
item
for
sublist
in
self
.
features
for
item
in
sublist
]
return
[
item
for
sublist
in
self
.
features
for
item
in
sublist
]
\ 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