Beispiel #1
0
def feature_extractor():

    #Abrir arquivo que vai receber as features dos arquivos de imagens
    file = "image_features_train_1.arff"
    text_file = open(file, "a")
    trainPath = "C:/Python27/ARP/Dataset/train2"
    dirList = os.listdir(trainPath)
    edge = EdgeHistogramFeatureExtractor(1)
    for dirName in dirList:
        fileList = os.listdir(trainPath + '/' + dirName)
        maxsize = len(fileList)
        for i in range(0, maxsize):
            #print fileList[i]
            filePATH = (trainPath + '/' + dirName + '/' + fileList[i])
            img = Image(filePATH)
            #Feature - Edge histogram
            edge_vecs = edge.extract(img)
            edge_fields = edge.getFieldNames()
            for y in range(0, edge.getNumFields()):
                #print edge_fields[y], '=', edge_vecs[y]
                text_file.write(str(edge_vecs[y]) + ",")
            #Feature - Hue
            #hue = HueHistogramFeatureExtractor(10)
            #hue_vecs = hue.extract(img)
            #hue_fields = hue.getFieldNames()
            #for i in range(0, hue.getNumFields()):
            #print hue_fields[i], '=', hue_vecs[i]
            #text_file.write(str(hue_vecs[i]) + ",")
            text_file.write(dirName + "\n")
    text_file.close()
def extract_edges(image, data, slices):
    edgeExtractor = EdgeHistogramFeatureExtractor(bins=4)
    image_bins = split_image_into_slices(image, slices)
    data["edge-angles"] = []
    data["edge-lengths"] = []
    for image_bin in image_bins:
        edge_angles_and_lengths = edgeExtractor.extract(image_bin)
        data["edge-angles"] += edge_angles_and_lengths[: len(edge_angles_and_lengths) / 2]
        data["edge-lengths"] += edge_angles_and_lengths[len(edge_angles_and_lengths) / 2 :]
    return data
Beispiel #3
0
def edge():
    edgeFeats = EdgeHistogramFeatureExtractor()
    a = np.array(edgeFeats.extract(watchman.imgbank[0])) 

    if len(watchman.imgbank) > 1:
        b = np.array(edgeFeats.extract(watchman.imgbank[1]))
    else:
        b = np.array(edgeFeats.extract(watchman.imgbank[0]))
        
    AandB = np.sum(np.square((a-b))) 
    return AandB
Beispiel #4
0
def edge():
    edgeFeats = EdgeHistogramFeatureExtractor()
    a = np.array(edgeFeats.extract(watchman.imgbank[0]))

    if len(watchman.imgbank) > 1:
        b = np.array(edgeFeats.extract(watchman.imgbank[1]))
    else:
        b = np.array(edgeFeats.extract(watchman.imgbank[0]))

    AandB = np.sum(np.square((a - b)))
    return AandB
Beispiel #5
0
def EHDFeatures(image):
    """
    Function that calculate the edge histogram of an image.

    Coded by An Li
    """

    img1 = Image(image)

    edgeFeats = EdgeHistogramFeatureExtractor(bins=16)

    results = np.array(edgeFeats.extract(img1), dtype=np.float32)

    return results
 def getFeatureExtractors(self):
     hueHistogramFeatureExtractor = HueHistogramFeatureExtractor(10)
     edgeHistogramFeatureExtractor = EdgeHistogramFeatureExtractor(10)
     haarLikeFeatureExtractor = HaarLikeFeatureExtractor(
         fname='/Users/burton/Downloads/SimpleCV/SimpleCV/Features/haar.txt'
     )
     return [
         hueHistogramFeatureExtractor, edgeHistogramFeatureExtractor,
         haarLikeFeatureExtractor
     ]
Beispiel #7
0
 def createExtractor(self, extractorName, trainPaths=[]):
     if (extractorName == 'hue'):
         extractor = HueHistogramFeatureExtractor(10)
     elif (extractorName == 'edge'):
         extractor = EdgeHistogramFeatureExtractor(10)
     elif (extractorName == 'haar'):
         extractor = HaarLikeFeatureExtractor(fname='haar.txt')
     elif (extractorName == 'bof'):
         extractor = BOFFeatureExtractor()
         extractor.generate(trainPaths, imgs_per_dir=40)
         # need to build the vocabuary (feature words) for bag of feature
         # extractor.generate(trainPaths, imgs_per_dir=40)
     return extractor
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import AdaBoostClassifier
from sklearn import cross_validation

from SimpleCV import Image
from SimpleCV import HueHistogramFeatureExtractor
from SimpleCV import HaarLikeFeatureExtractor
from SimpleCV import EdgeHistogramFeatureExtractor

import numpy as np
from glob import glob
import pickle

# model to extract feature
hhfe = HueHistogramFeatureExtractor(10)
ehfe = EdgeHistogramFeatureExtractor(10)
haarfe = HaarLikeFeatureExtractor('haar.txt')

# Give path of the training folder
images = glob('./fruits/*')


# Extract features and target labels for training
def get_feature_labels():
    features = list()
    labels = list()
    for im in images:
        try:
            img = Image(im)
            labels.append(im[:-2])
            features.append(