...
 
Commits (10)
# Title: Inovitaxon
## Author: Hemerson Pistori
## Summary:
Code in python that extracts several attributes and generates an arff to be processed by weka. The goal is to extract all attributes implemented in OpenCV and in scikit-image.
### Extracted Attributes:
1. Attributes of Color RGB, HSV, Cielab (Mín., Máx., média e Desvio)
2. Shape descriptor, invariant to scale, translation and rotation: 7 Hu moments
3. Texture Attributes - GLCM (contrasts, dissimilarities, homogeneities, asm, energies, correlations)
4. Shape and orientation: HOG
5. Texture Attributes: LPB
## Dependences
### Linux
- kubuntu trusty 14.04.2 TLS
- Python 2.7.6
- scikit-image
- Opencv 2.7
### Windows
- Install [Anaconda](http://continuum.io/downloads) "Contains all dependences".
## Install OpenCV
### Linux
Instructions: [OpenCV-Linux](http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation).
```
$ sudo apt-get install python-opencv
```
### Windows
- [OpenCV-Python](https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows).
1. Download [Opencv](https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows)
2. Extract Files for directory.
3. Go file opencv/build/python/2.7.
4. Copy file cv2.pyd para C:/Python27/lib/site-packeges.
5. Open CMD type it python.
6. Type it:
```
>>> import cv2
>>> print cv2.__version__
```
Ok!
## Install scikit-image e arff
```
$ sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose python-pip python-networkx
$ sudo pip install -U scikit-image
```
For upgrad pip
```
$ python -m pip install --upgrade pip setuptools wheel
```
## How to use
- Create a new folder inside the 'date' folder with your image bank
$ cd src
```
- Run the code that extracts attributes by passing the names of your image bank as parameter
```
$ python ./extraiAtributos.py name_your_image_bank
```
- The arff file will be generated inside the folder of your image bank
......@@ -5,19 +5,8 @@
Nome: extratores.py
Autor: Hemerson Pistori (pistori@ucdb.br)
Descricão: Define a classe Extratores que faz a ponte com os diversos extratores de
atributos implementados no OpenCV e no scikit-image. É aqui que devem ser inseridos
novos códigos para fazer a ponte com novos atributos.
Modo de Usar:
- Copie e cole uma das funções que já implementam algum extrator
- Altere o nome e modifique o código naquilo que for necessário
- Coloque o nome do extrator, que deve ser igual à função, na lista de extratores construída
logo no início da classe dentro da variável extratores (não esqueça do "self")
- Coloque a sigla do extrator na lista criada logo abaixo dos nomes dos extratores
"""
"""
from __future__ import print_function
import numpy as np
......@@ -212,61 +201,6 @@ class Extratores(object):
return nomes, tipos, list(valores)
def filtrosGabor(self):
"""
Extrai Atributos Filtros de Gabor
"""
names = []
results2 = []
def compute_feats(image, kernels):
#np.zeros(forma, tipo, ordem'opcional)-> Retorna uma nova matriz de det forma e tipo, cheio de zeros
feats = np.zeros((len(kernels), 2), dtype=np.double)
for k, kernel in enumerate(kernels): #enumerate-> Retorna uma tupla contendo uma contagem
filtered = ndi.convolve(image, kernel, mode='wrap') #ndi.convolve-> Retorna o resul da convolução de entrada com pesos
feats[k, 0] = filtered.mean()
feats[k, 1] = filtered.var()
results2.append(feats[k, 0])
#print ("Mean: %.4f" % feats[k, 0])
results2.append(feats[k, 1])
#print ("Variance: %.4f" % feats[k, 1])
return feats #feats é uma matriz
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)
#Prepare filter bank kernels
indice = 0
kernels = []
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 tipo in ("Mean", "Variance"):
names.append("Thet_%f_Sigma_%i_Frequencia_%.2f_%s" % (theta, sigma, frequency, tipo))
#Takes pictures
shrink = (slice(0, None, 3), slice(0, None, 3))
image = img_as_float(self.imagemTonsDeCinza)[shrink]
compute_feats(image,kernels)
tipos = [numerico] * len(names)
return names, tipos, results2
def extrai_todos(self, imagem):
"""
......@@ -279,7 +213,7 @@ class Extratores(object):
"""
extratores = [self.momentos, self.estatisticas_cores, self.matriz_coocorrencia, self.hog, self.lbp, self.filtrosGabor]
extratores = [self.momentos, self.estatisticas_cores, self.matriz_coocorrencia, self.hog, self.lbp]
todosNomesAtributos = []
todosTiposAtributos = []
......