Example #1
0
def make_project_file(name, k, session):
    import image_segment
    import file_handling

    img = file_handling.get_target_image(name)
    labels = image_segment.segment(img, k)

    target_image = TargetImage(name=name, pixels=img, labels=labels)
    session.merge(target_image)
    session.commit()
    return target_image
Example #2
0
def search_exhaustively():
    img = ndimage.imread('butterfly.jpg')
    img = misc.imresize(img, size=0.125)

    env = ndimage.imread('box-turtle.jpeg')
    env = misc.imresize(env, size=1.0)

    search_env = env
    patch_src = img
    K = 50
    labels = image_segment.segment(img, K)
    patch_indices = labels == 15

    searcher = RlSearch(search_env, patch_src, patch_indices)

    searcher.search_exhaustively()
Example #3
0
def search_smartly():
    img = ndimage.imread('butterfly.jpg')
    img = misc.imresize(img, size=0.0625)

    env = ndimage.imread('box-turtle.jpeg')
    env = misc.imresize(env, size=0.25)

    search_env = img
    patch_src = img
    K = 50
    labels = image_segment.segment(img, K)
    patch_indices = labels == 15

    searcher = RlSearch(search_env, patch_src, patch_indices)
    searcher.run(N_Terminator(200))
    print searcher.Q
    print searcher.state
    searcher.display()
from matplotlib import pyplot as plt
import matplotlib.patches as mpatch
import numpy as np





if __name__ == "__main__":
    img = ndimage.imread('butterfly.jpg')
    img = misc.imresize(img, size = 0.0625)
    
    search_env = img
    patch_src = img
    K = 50
    labels = image_segment.segment(img, K)

    label = 40
    x_ndx, y_ndx = np.where(labels == label)
    bbox = np.min(x_ndx), np.max(x_ndx), np.min(y_ndx), np.max(y_ndx)
    modded = np.copy(img)
    modded[labels != label] = [0,0,0]
    weights = modded[bbox[0] : bbox[1] , bbox[2] : bbox[3]] / 255.

    output = ndimage.filters.convolve(img / 255., weights, mode='constant',cval=0.0)

    fig1 = plt.figure(figsize=(5, 5))
    ax1 = fig1.add_subplot(211)
    output = np.dot(output[...,:3], [0.299, 0.587, 0.114]) # greyscale
    ax1.imshow(output, alpha = 1.0)