Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
inovisao
pynovisao
Commits
9777b072
Commit
9777b072
authored
Dec 05, 2017
by
Hemerson Pistori
Browse files
novo fonte com o extrator de gabor
parent
ba32dba9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
src/extraction/gabor.py
src/extraction/gabor.py
+99
-0
No files found.
src/extraction/gabor.py
0 → 100644
View file @
9777b072
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
Extract Gabor features.
Hans G. Feichtinger, Thomas Strohmer: "Gabor Analysis and Algorithms", Birkhäuser, 1998
Name: gabor.py
Author: Hemerson Pistori (pistori@ucdb.br)
Based on: https://github.com/riaanvddool/scikits-image/blob/master/doc/examples/plot_gabor.py
"""
import
numpy
as
np
from
util.utils
import
ImageUtils
from
extractor
import
Extractor
from
scipy
import
ndimage
as
ndi
from
skimage
import
feature
from
skimage.filter
import
gabor_kernel
from
skimage.util
import
img_as_float
class
GABOR
(
Extractor
):
"""Implements GABOR feature extraction."""
def
__init__
(
self
):
pass
def
run
(
self
,
image
):
"""Extract GABOR features.
Parameters
----------
image : opencv image
Image to be analyzed.
Returns
-------
features : tuple
Returns a tuple containing a list of labels, type and values for each feature extracted.
"""
def
compute_feats
(
image
,
kernels
):
feats
=
np
.
zeros
((
len
(
kernels
),
2
),
dtype
=
np
.
double
)
for
k
,
kernel
in
enumerate
(
kernels
):
filtered
=
ndi
.
convolve
(
image
,
kernel
,
mode
=
'wrap'
)
feats
[
k
,
0
]
=
filtered
.
mean
()
feats
[
k
,
1
]
=
filtered
.
var
()
values
.
append
(
feats
[
k
,
0
])
values
.
append
(
feats
[
k
,
1
])
return
feats
def
power
(
image
,
kernel
):
image
=
(
image
-
image
.
mean
())
/
image
.
std
()
return
np
.
sqrt
(
ndi
.
convolve
(
image
,
np
.
real
(
kernel
),
mode
=
'wrap'
)
**
2
+
ndi
.
convolve
(
image
,
np
.
imag
(
kernel
),
mode
=
'wrap'
)
**
2
)
image_grayscale
=
ImageUtils
.
image_grayscale
(
image
,
bgr
=
True
)
shrink
=
(
slice
(
0
,
None
,
3
),
slice
(
0
,
None
,
3
))
image_float
=
img_as_float
(
self
.
image_grayscale
)[
shrink
]
#Prepare filter bank kernels
labels
=
[]
values
=
[]
kernels
=
[]
index
=
0
for
theta
in
range
(
4
):
theta
=
theta
/
4.
*
np
.
pi
for
sigma
in
(
1
,
3
):
for
frequency
in
(
0.05
,
0.25
):
kernel
=
np
.
real
(
gabor_kernel
(
frequency
,
theta
=
theta
,
sigma_x
=
sigma
,
sigma_y
=
sigma
))
kernels
.
append
(
kernel
)
print
(
"Thet_%f_Sigma_%i_Frequencia_%.2f"
%
(
theta
,
sigma
,
frequency
))
for
stat
in
(
"Mean"
,
"Variance"
):
labels
.
append
(
"Thet_%f_Sigma_%i_Frequencia_%.2f_%s"
%
(
theta
,
sigma
,
frequency
,
stat
))
compute_feats
(
image_float
,
kernels
)
types
=
[
'numeric'
]
*
len
(
labels
)
return
labels
,
types
,
values
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