コード例 #1
0
ファイル: sampling1.py プロジェクト: hudginspj/imagery
def rgbtest():
    raws, exps = reader.get_images()
    print(exps.keys())

    # rg = color.gray2rgb(adhist)
    # red_multiplier = [1, 0, 0]
    # yellow_multiplier = [1, 1, 0]
    # rg = red_multiplier * rg
    r = exps['04']
    g = exps['05']
    b = exps['06']
    zipped = np.dstack((r, g, b))
    io.imsave(OUTDIR + "/color.png", zipped)

    # r = exps['08']
    # g = exps['06']
    # b = exps['05']
    b2 = 1-(2*exps['05'])
    io.imsave(OUTDIR + "/inv.png", b2)

    io.imsave(OUTDIR + "/color2.png", 
        np.dstack((exps['08'], exps['05'], exps['06'])))
    io.imsave(OUTDIR + "/color3.png", 
        np.dstack((exps['04'], exps['05'], exps['08'])))
    io.imsave(OUTDIR + "/color4.png", 
        np.dstack((exps['08'], exps['05'], exps['04'])))
    io.imsave(OUTDIR + "/color6.png", 
        np.dstack((exps['04'], exps['08'], b2)))
    io.imsave(OUTDIR + "/true_color.png", 
        np.dstack((exps['04'], exps['03'], exps['02'])))
    io.imsave(OUTDIR + "/true_color_raw.png", 
        np.dstack((raws['04'], raws['03'], raws['02'])))
コード例 #2
0
ファイル: sampling1.py プロジェクト: hudginspj/imagery
def train(pos, neg):
    raws, exps = reader.get_images()

    # flat_raws = [ndarray.flatten(raw) for raw in raws.values()]    
    # print(flat_raws[0].shape)
    # flattened = np.dstack(flat_raws)[0]
    # print(flattened.shape, flattened[0])

    grid = np.dstack(raws.values())
    print(grid.shape)

    X = []
    y = []
    for p in pos:
        X.append(grid[p])
        y.append(1)

    for p in neg:
        X.append(grid[p])
        y.append(0)

    classifier = KNeighborsClassifier(1)
    classifier = RandomForestClassifier()
    classifier.fit(X, y)

    testpoints = list(coords("""
        553 298
        430 610
        500 300
        500 240
    """))
    testX = [grid[p] for p in testpoints]
    print(classifier.predict(testX))

    pred_image = np.zeros((800,800))
    for i in range(800):
        print(i)
        # for j in range(800):
        pred_image[i] = classifier.predict(grid[i])
    
    io.imsave(OUTDIR + '/pred.png', pred_image)

    orig = exps['08']
    r = copy.copy(orig)
    g = copy.copy(orig)
    b = copy.copy(orig)

    b = b + pred_image
    b = np.vectorize(lambda x: min(x, 1.0))(b)

    overlay = np.dstack((r, g, b))
    io.imsave(OUTDIR + '/pred_overlay.png', overlay)
コード例 #3
0
ファイル: sampling1.py プロジェクト: hudginspj/imagery
def show_sample(pos, neg):
    raws, exps = reader.get_images()

    orig = exps['08']
    r = copy.copy(orig)
    g = copy.copy(orig)
    b = copy.copy(orig)

    for p in pos:
        r[p] = 1

    for p in neg:
        g[p] = 1

    zipped = np.dstack((r, g, b))
    io.imsave(OUTDIR + '/sample.png', zipped)
コード例 #4
0
ファイル: grid.py プロジェクト: hudginspj/imagery
def make_grid():
    raws, exps = reader.get_images()

    orig = exps['08']
    r = copy.copy(orig)
    g = copy.copy(orig)
    b = copy.copy(orig)

    for i in range(800):
        for j in range(800):

            if i % 500 == 0 or j % 500 == 0:
                b[i, j] = 1
            elif i % 100 == 0 or j % 100 == 0:
                r[i, j] = 1
            elif i % 10 == 0 and j % 10 == 0:
                g[i, j] = 1

    #b = np.vectorize(lambda x: min(x, 1.0))(b)

    zipped = np.dstack((r, g, b))
    io.imsave(OUTDIR + '/s_grid.png', zipped)
コード例 #5
0
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
from keras.models import Sequential
from keras.layers import Input, Dense, Dropout, Flatten
import pydot
import graphviz

# GET DATA
from reader import get_images
(x_train, y_train), (x_test, y_test) = get_images()
num_classes = 10
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

# DEFINE PARAMETERS
nInput = [10]
nHidden = [200]
lossFunct = ["categorical_crossentropy"]
opt = ["adam"]
metric = ["accuracy"]
batchSize = [150]
epoch = [10]

# DEFINE DATA STRUCTURE TO HOLD OPTIMAL COMBINATION
bestParams = [None, None, None, None, None, None, None]
bestScenario = (bestParams, 0)

#COUNT TOTAL NUMBER OF ITERATIONS
コード例 #6
0
ファイル: training.py プロジェクト: hudginspj/imagery
    return red_points, green_points


def overlay(rps, gps, b_image, exp, fn):
    # raws, exps = reader.get_images()

    r = copy.copy(exp)
    g = copy.copy(exp)
    b = copy.copy(exp)

    for p in rps:
        r[p] = 1

    for p in gps:
        g[p] = 1

    b = b + b_image
    b = np.vectorize(lambda x: min(x, 1.0))(b)

    overlay = np.dstack((r, g, b))
    io.imsave(OUTDIR + '/' + fn, overlay)


pos, neg = get_sample("out/train8.png")

raws, exps = reader.get_images(3500, 3900, 800, 1200)
# show_sample(pos, neg)
pred_image = train(pos, neg, raws)
overlay(pos, neg, 0.5 * pred_image, exps['05'], 'pred_and_train.png')
overlay([], [], 0.5 * pred_image, exps['08'], 'pred_overlay.png')