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
46064a71
Commit
46064a71
authored
Sep 10, 2020
by
Diego André Sant'Ana
🤞
Browse files
fix problem with python3 and extractor features
parent
c20dd737
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
src/extraction/feature_extraction.py
src/extraction/feature_extraction.py
+7
-10
src/extraction/image_moments.py
src/extraction/image_moments.py
+11
-7
No files found.
src/extraction/feature_extraction.py
View file @
46064a71
...
...
@@ -173,10 +173,7 @@ class FeatureExtractor(object):
raise
IException
(
"Image %s is possibly corrupt"
%
filepath
)
if
len
(
self
.
data
)
>
0
:
if
sys
.
version_info
>=
(
3
,
0
):
values
=
list
(
zip
(
*
([
extractor
().
run
(
image
)
for
extractor
in
self
.
extractors
])))
else
:
values
=
list
(
itertools
.
chain
.
from_iterable
(
zip
(
*
([
extractor
().
run
(
image
)
for
extractor
in
self
.
extractors
]))[
2
]))
values
=
list
(
itertools
.
chain
.
from_iterable
(
zip
(
*
([
extractor
().
run
(
image
)[
2
]
for
extractor
in
self
.
extractors
]))))
self
.
data
.
append
(
values
+
[
cl
if
cl
in
classes
else
classes
[
0
]])
...
...
@@ -258,19 +255,19 @@ class FeatureExtractor(object):
"""
arff
=
open
(
output_file
,
'wb'
)
arff
.
write
(
bytes
(
str
(
"%s %s
\n\n
"
%
(
'@relation'
,
relation
))
,
'utf-8'
))
arff
.
write
(
str
(
"%s %s
\n\n
"
%
(
'@relation'
,
relation
))
.
encode
(
'utf-8'
))
for
label
,
t
in
zip
(
labels
,
types
):
arff
.
write
(
bytes
(
str
(
"%s %s %s
\n
"
%
(
'@attribute'
,
label
,
t
))
,
'utf-8'
))
arff
.
write
(
str
(
"%s %s %s
\n
"
%
(
'@attribute'
,
label
,
t
))
.
encode
(
'utf-8'
))
arff
.
write
(
bytes
(
str
(
"%s %s {%s}
\n\n
"
%
(
'@attribute'
,
'classe'
,
', '
.
join
(
classes
))),
'utf-8'
))
arff
.
write
(
bytes
(
str
(
'@data
\n\n
'
),
'utf-8'
))
arff
.
write
(
str
(
"%s %s {%s}
\n\n
"
%
(
'@attribute'
,
'classe'
,
', '
.
join
(
classes
))).
encode
(
'utf-8'
))
arff
.
write
(
str
(
'@data
\n\n
'
).
encode
(
'utf-8'
))
#print(data)
for
instance
in
data
:
instance
=
map
(
str
,
instance
)
line
=
","
.
join
(
instance
)
arff
.
write
(
bytes
(
str
(
line
+
"
\n
"
)
,
'utf-8'
))
arff
.
write
(
str
(
line
+
"
\n
"
)
.
encode
(
'utf-8'
))
arff
.
close
()
...
...
src/extraction/image_moments.py
View file @
46064a71
...
...
@@ -43,22 +43,26 @@ class RawCentralMoments(Extractor):
"""
#raw_moments = moments(image)
image_binary
=
ImageUtils
.
image_binary
(
image
,
bgr
=
True
)
m
=
measure
.
moments
(
image_binary
)
m
=
np
.
nan_to_num
(
m
)
values_m
=
[
m
[
p
,
q
]
for
(
p
,
q
)
in
self
.
_moments_order
]
labels_m
=
[
M
+
str
(
p
)
+
str
(
q
)
for
M
,(
p
,
q
)
in
zip
([
'M_'
]
*
len
(
self
.
_moments_order
),
self
.
_moments_order
)]
labels_m
=
[
M
+
str
(
p
)
+
str
(
q
)
for
M
,(
p
,
q
)
in
zip
([
'M_'
]
*
len
(
self
.
_moments_order
),
self
.
_moments_order
)]
row
=
m
[
0
,
1
]
/
m
[
0
,
0
]
col
=
m
[
1
,
0
]
/
m
[
0
,
0
]
mu
=
measure
.
moments_central
(
image_binary
,
center
=
(
row
,
col
),
order
=
3
)
mu
=
np
.
nan_to_num
(
mu
)
values_mu
=
[
mu
[
p
,
q
]
for
(
p
,
q
)
in
self
.
_moments_order
]
labels_mu
=
[
M
+
str
(
p
)
+
str
(
q
)
for
M
,(
p
,
q
)
in
zip
([
'Mu_'
]
*
len
(
self
.
_moments_order
),
self
.
_moments_order
)]
#print(values_mu)
labels
=
labels_m
+
labels_mu
types
=
[
Extractor
.
NUMERIC
]
*
len
(
labels
)
values
=
values_m
+
values_mu
...
...
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