Exemplo n.º 1
0
import image_operations as operations
import feature_extraction as extraction
from skimage import feature, color, exposure
import feature_validation as validation

training_images, training_labels, training_classes = data_loading.loadTrainingImagesPoleNumbersAndClasses(
)
size = 100

print("resizing...")
resized = util.loading_map(lambda x: operations.cropAndResize(x, 0, size),
                           training_images)
print("hsv...")
hsv = util.loading_map(color.rgb2hsv, resized)
print("grayscaling...")
grayscaled = util.loading_map(color.rgb2gray, resized)

print("colors")
colors = util.loading_map(
    lambda x: extraction.split_image_features(
        extraction.calculateColorFeatures, 7, x), hsv)

n_folds = 5

print("evaluating colors")
model = DistanceModel()
#from sklearn.linear_model import LogisticRegression
#model = LogisticRegression(solver = 'lbfgs', multi_class = 'multinomial')
validation.validate_feature(colors, training_labels, training_classes, model,
                            n_folds, False, False, True, True)
print('\a')
Exemplo n.º 2
0
hed = util.loading_map(color.rgb2hed, resized)
print("rgbcie...")
cie = util.loading_map(color.rgb2rgbcie, resized)
print("grayscaling...")
grayscaled = util.loading_map(color.rgb2gray, resized)
print("normalising...")
normalized = util.loading_map(exposure.equalize_hist, grayscaled)
#print("edges...")
#edges = util.loading_map(feature.canny, grayscaled)

print("brightness features")
brightness = util.loading_map(extraction.calculateDarktoBrightRatio, resized)
print('\a')
print("hsv features")
hsv_features = util.loading_map(
    lambda x: extraction.split_image_features(
        extraction.calculateColorFeatures, 8, x), hsv)
print("luv features")
luv_features = util.loading_map(lambda x: extraction.pixel_features(x, 11),
                                luv)
#luv_features = util.loading_map(lambda x: extraction.split_image_features(
#    lambda y : extraction.color_features(y, mean = True, std = True), 7, x), luv)
print("hed features")
hed_features = util.loading_map(
    lambda x: extraction.split_image_features(
        lambda y: extraction.color_features(y, mean=True, std=True), 8, x),
    hed)
print("rgbcie features")
cie_features = util.loading_map(
    lambda x: extraction.split_image_features(
        extraction.calculateColorFeatures, 8, x), cie)
print("hog features")
for i in range(1, 14, 2):
    print("hsv", i)
    hsv_f = util.loading_map(lambda x: extraction.pixel_features(x, i), hsv)
    validation.validate_feature(hsv_f, labels, classes, model, n_folds, False,
                                False, True, True)

for i in range(1, 14, 2):
    print("luv", i)
    luv_f = util.loading_map(lambda x: extraction.pixel_features(x, i), luv)
    validation.validate_feature(luv_f, labels, classes, model, n_folds, False,
                                False, True, True)

#With STD
print("rgb 11 + std")
rgb_11_std = util.loading_map(
    lambda x: extraction.split_image_features(
        lambda y: extraction.color_features(y, mean=True, std=True), 11, x),
    resized)
#validation.validate_feature(rgb_11_std, labels, classes, model, n_folds, False, False, True, True)
print("hsv 11 + std")
hsv_11_std = util.loading_map(
    lambda x: extraction.split_image_features(
        lambda y: extraction.color_features(y, mean=True, std=True), 11, x),
    hsv)
#validation.validate_feature(hsv_11_std, labels, classes, model, n_folds, False, False, True, True)
print('\a')
print("luv 11 + std")
luv_11_std = util.loading_map(
    lambda x: extraction.split_image_features(
        lambda y: extraction.color_features(y, mean=True, std=True), 11, x),
    luv)
#validation.validate_feature(luv_11_std, labels, classes, model, n_folds, False, False, True, True)
Exemplo n.º 4
0
                           images)
print("normalizing...")
normalized = util.loading_map(operations.normalizeImage, resized)
print("grayscaling...")
grayscale = util.loading_map(color.rgb2gray, resized)
#print("reducing color space...")
#reduced = util.loading_map(operations.reduceColorSpace, resized)

#feature extraction
#print("color features...")
#color_features                  = util.loading_map(extraction.color_features, resized)
#print("normalized color features...")
#normalized_color_features       = util.loading_map(extraction.color_features, normalized)
print("mean channels features...")
split_color_features = util.loading_map(
    lambda x: extraction.split_image_features(extraction.color_features, 3, x),
    resized)
print("moment channel features...")
moment_channel_features = util.loading_map(
    lambda x: extraction.split_image_features(
        lambda y: extraction.color_features(y, True, True, True, True), 3, x),
    resized)
#print("split normalized color features...")
#split_normalized_color_features = util.loading_map(lambda x: extraction.split_image_features(extraction.color_features, 3, x), normalized)
#print("angle features")
#angle_features         = util.loading_map(lambda x : extraction.calculateAngleFeatures(x, 7), resized)
print("weighted angle features")
weighted_angle_features = util.loading_map(
    lambda x: extraction.weightedAngleFeatures(x, 7), resized)
print("Perceived brightness features")
brightness_features = util.loading_map(extraction.calculateDarktoBrightRatio,
Exemplo n.º 5
0
print("luv...")
luv =  [color.rgb2luv(img) for img in resized]
print("hed...")
hed =  [color.rgb2hed(img) for img in resized]

print("grayscaling...")
grayscaled =  [color.rgb2gray(img) for img in resized]
#print("edges...")

print("brightness features")
brightness = util.loading_map(extraction.calculateDarktoBrightRatio, resized)

print("luv features")

luv_features = util.loading_map(lambda x: extraction.split_image_features(
    lambda y : extraction.color_features(y, mean = True, std = True), 7, x), luv)
print('\a')
print("hed features")
hed_features = util.loading_map(lambda x: extraction.split_image_features(
    lambda y : extraction.color_features(y, mean = True, std = True), 8, x), hed)

print("hog features")
hog = util.loading_map(lambda x: feature_extraction.calcHOGWrapper(x), grayscaled)



hybrid_bright_hed_hog_luv = numpy.concatenate((brightness, hed_features, hog, luv_features), 1)


n_folds=5
print("Build random forest")
#preloading
print("loading train data...")
#images, classes = loader.loadUniqueTrainingAndClasses()
images, classes = loader.loadTrainingAndClasses()
amount = len(images)
print("resizing...")
resized = util.loading_map(lambda x: operations.cropAndResize(x, 0, 50),
                           images)
print("normalizing...")
normalized = util.loading_map(operations.normalizeImage, resized)
print("grayscaling...")
grayscale = util.loading_map(color.rgb2gray, resized)

print("mean channels features...")
split_color_features = util.loading_map(
    lambda x: extraction.split_image_features(extraction.color_features, 3, x),
    resized)

print("weighted angle features")
weighted_angle_features = util.loading_map(
    lambda x: extraction.weightedAngleFeatures(x, 7), resized)
print("Perceived brightness features")
brightness_features = util.loading_map(extraction.calculateDarktoBrightRatio,
                                       resized)
print("High Pass Frequency features")
frequency_features = util.loading_map(
    lambda x: extraction.frequencyFeatures(x, selectedclasses=[22, 23])[1::8],
    grayscale)

combined_features_train = []
for i in range(amount):