Commit 46064a71 authored by Diego André Sant'Ana's avatar Diego André Sant'Ana 🤞
Browse files

fix problem with python3 and extractor features

parent c20dd737
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment