Commit 9777b072 authored by Hemerson Pistori's avatar Hemerson Pistori
Browse files

novo fonte com o extrator de gabor

parent ba32dba9
# -*- coding: utf-8 -*-
Extract Gabor features.
Hans G. Feichtinger, Thomas Strohmer: "Gabor Analysis and Algorithms", Birkhäuser, 1998
Author: Hemerson Pistori (
Based on:
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):
def run(self, image):
"""Extract GABOR features.
image : opencv image
Image to be analyzed.
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))
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))
types = ['numeric'] * len(labels)
return labels, types, values
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