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
5d5fa1f0
Commit
5d5fa1f0
authored
13 years ago
by
unknown
Browse files
Options
Downloads
Patches
Plain Diff
kleuren plaatjes worden omgezet naar grijswaarden, zwart wit plaatjes
niet
parent
56fc1ca9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/GrayscaleImage.py
+12
-6
12 additions, 6 deletions
src/GrayscaleImage.py
src/LBP.py
+0
-74
0 additions, 74 deletions
src/LBP.py
src/LocalBinaryPatternizer.py
+1
-6
1 addition, 6 deletions
src/LocalBinaryPatternizer.py
with
13 additions
and
86 deletions
src/GrayscaleImage.py
+
12
−
6
View file @
5d5fa1f0
from
pylab
import
imshow
,
imread
,
show
from
scipy.misc
import
imresize
from
scipy.misc
import
imresize
,
imsave
class
GrayscaleImage
:
def
__init__
(
self
,
image_path
=
None
,
data
=
None
):
if
image_path
!=
None
:
if
image_path
:
self
.
data
=
imread
(
image_path
)
self
.
convert_to_grayscale
()
elif
data
!=
None
:
elif
data
:
self
.
data
=
data
def
__iter__
(
self
):
...
...
@@ -29,7 +29,8 @@ class GrayscaleImage:
return
self
.
data
[
position
]
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
):
self
.
data
=
self
.
data
[
rectangle
.
y
:
rectangle
.
y
+
rectangle
.
height
,
...
...
@@ -39,21 +40,26 @@ class GrayscaleImage:
imshow
(
self
.
data
,
cmap
=
"
gray
"
)
show
()
# size is of type float
def
resize
(
self
,
size
):
def
resize
(
self
,
size
):
# size is of type float
self
.
data
=
imresize
(
self
.
data
,
size
)
def
get_shape
(
self
):
return
self
.
data
.
shape
shape
=
property
(
get_shape
)
def
get_width
(
self
):
return
self
.
get_shape
()[
1
]
width
=
property
(
get_width
)
def
get_height
(
self
):
return
self
.
get_shape
()[
0
]
height
=
property
(
get_height
)
def
in_bounds
(
self
,
y
,
x
):
return
x
>=
0
and
x
<
self
.
width
and
y
>=
0
and
y
<
self
.
height
def
save
(
self
,
path
):
imsave
(
path
,
self
.
data
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/LBP.py
deleted
100755 → 0
+
0
−
74
View file @
56fc1ca9
#!/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
()
This diff is collapsed.
Click to expand it.
src/LocalBinaryPatternizer.py
+
1
−
6
View file @
5d5fa1f0
...
...
@@ -9,7 +9,6 @@ class LocalBinaryPatternizer:
self
.
image
=
image
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
)))
...
...
@@ -19,7 +18,6 @@ class LocalBinaryPatternizer:
for
j
in
xrange
(
cells_in_width
):
self
.
features
[
i
].
append
(
Histogram
(
256
,
0
,
256
))
def
create_features_vector
(
self
):
'''
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
...
...
@@ -40,14 +38,11 @@ class LocalBinaryPatternizer:
return
self
.
get_features_as_array
()
def
is_pixel_darker
(
self
,
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
]
return
[
item
for
sublist
in
self
.
features
for
item
in
sublist
]
\ No newline at end of file
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