Exemplo n.º 1
0
def experiment_yen_threshold(image=None):
    images = image_generator()
    if image is not None:
        img_path = os.path.join(BASE_DIR, "data/imgs/")
        fn = os.path.join(img_path, image)
        im = load_images([fn])[0].astype("int32")
        images = itertools.chain([(fn, im)], images)

    for fn, im in images:
        imgs = [im]
        titles = ["Original"]
        print("computing yen threshold")
        yen = threshold_yen(im)
        channels = threshold_by_channel(im, yen)
        titles.append("Yen Thresholded")
        imgs.append(channels[0])

        for cp in [175, 200, 225, 250]:
            titles.append("Cutpoint %d" % cp)
            print("cutting")
            rtn = np.zeros(im.shape)
            rtn[np.average(im, axis=2, weights=[0.7, 0.1, 0.2]) > cp, 0] = 255
            for i in range(1, 3):
                rtn[:, :, i] = rtn[:, :, 0]

            imgs.append(rtn)

        print("plotting")
        plot_images(imgs, titles=titles, suptitle=fn.split("/")[-1])
Exemplo n.º 2
0
def add_image_to_image_generator(images, file=None):
    if file is not None:
        path = os.path.join(BASE_DIR, "data/imgs/")
        path = os.path.join(path, file)
        image = load_images(path).astype("int32")
        images = itertools.chain([(path, image)], images)

    return images
Exemplo n.º 3
0
def image_generator():
    csv_path = os.path.join(BASE_DIR, "data/train.csv")
    img_path = os.path.join(BASE_DIR, "data/imgs/")

    images = os.listdir(img_path)
    shuffle(images)
    for idx, im in enumerate(images):
        im = os.path.join(img_path, im)
        image = load_images([im])[0].astype("int32")
        yield im, image
Exemplo n.º 4
0
def main(csv_path=os.path.join(BASE_DIR, 'data/train.csv'),
         img_path=os.path.join(BASE_DIR, 'data/imgs/')):

    whale_index = pd.read_csv(csv_path)
    image_file_names = lookup_whale_images(whale_index, whale_id='whale_78785')
    image_arrays = load_images(image_file_names)

    image_file = image_file_names[0]
    image = image_arrays[0]

    resized_array = resize_images(image_arrays)
    transformed_array = transform_images(resized_array)

    t_im_1 = transformed_array[0].reshape((3, 300, 300)).transpose(1, 2, 0)
    t_im_2 = transformed_array[1].reshape((3, 300, 300)).transpose(1, 2, 0)
    plot_images([t_im_1, t_im_2],['transformed image 1','transformed image 2'])