def run_foa(sample, gt):

    # Import image
    test_image = foai.ImageObject(sample, rgb=False)
    test_image.ground_truth = gt

    # Generate Gaussian Blur Prior - Time ~0.0020006
    foveation_prior = foac.matlab_style_gauss2D(test_image.modified.shape, 300)

    # Generate Gamma Kernel
    k = np.array([1, 9], dtype=float)
    mu = np.array([0.2, 0.5], dtype=float)
    kernel = foac.gamma_kernel(mask_size=(14, 14), k=k, mu=mu)
    # plt.imshow(kernel)

    # Generate Saliency Map
    foac.convolution(test_image, kernel, foveation_prior)

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(test_image, rank_count=3, bbox_size=(28, 28))

    test_image.draw_image_patches()
    test_image.plot_main()
    test_image.plot_patches()
    plt.show()

    return test_image
Exemple #2
0
def run_foa(sample, prior, kernel, bbox=(28, 28)):

    # Import image
    img = foai.ImageObject(sample, rgb=False)

    # Generate Saliency Map
    foac.convolution(img, kernel, prior)

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(img, rank_count=1, bbox_size=bbox)
    img.draw_image_patches()
    # img.plot_main()
    
    # Pad patches to be the same size (28x28)
    patch = img.patch_list[0]
    if (patch.shape != bbox):
        pad = np.zeros(bbox)
        pad[:patch.shape[0], :patch.shape[1]] = patch
        patch = pad

    return patch.reshape(1, bbox[0], bbox[1])
def run_foa_svhn(input=SVHNImage, tf=int, gt=None, k=None, mu=None):
    assert (input.image is not None)
    img = np.array(input.image)
    x_dim = img.shape[0]
    y_dim = img.shape[1]
    print(np.array(img.shape))

    # Load Image Object
    img = foai.ImageObject(img)
    img.ground_truth = gt

    # Generate Gaussian Blur Prior - Time ~0.0020006
    foveation_prior = foac.matlab_style_gauss2D(img.modified.shape, 300)

    # Generate Gamma Kernel
    # k = np.array([1, 26, 1, 25, 1, 19], dtype=float)
    # mu = np.array([2, 2, 1, 1, 0.5, 0.5], dtype=float)
    k = np.array([1, 5, 1, 9, 1, 13], dtype=float)
    mu = np.array([0.8, 0.7, 0.3, 0.5, 0.1, 0.3], dtype=float)
    kernel = foac.gamma_kernel(img, mask_size=(32, 32), k=k, mu=mu)

    # Generate Saliency Map
    start = time.time()
    foac.convolution(img, kernel, foveation_prior)
    stop = time.time()
    print(f"Salience Map Generation: {stop - start} seconds")

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(img, rank_count=4, bbox_size=(y_dim // 4, y_dim // 4))
    bbt = 2
    if (x_dim < 100 and y_dim < 100):
        bbt = 1

    img.draw_image_patches(bbt=bbt)

    # Threshold
    img.salience_map = np.where(img.salience_map > tf, img.salience_map, 0)

    img.plot_main()
    img.plot_patched_map()
Exemple #4
0
    # %% Generate Saliency Map

    # Generate Gaussian Blur Prior - Time ~0.0020006
    foveation_prior = foac.matlab_style_gauss2D(testIMG.modified.shape, 300)

    # Generate Gamma Kernel
    kernel = foac.gamma_kernel(testIMG)

    # Generate Saliency Map
    start = time.time()
    foac.foa_convolution(testIMG, kernel, foveation_prior)
    stop = time.time()
    print("Salience Map Generation: ", stop - start, " seconds")

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(testIMG, rankCount=5)

    # %% Plot Results

    # Plot Bounding Box Patches
    testIMG.draw_image_patches()
    testIMG.save_image_patches()

    # Create a figure with 2 subplots
    fig, (ax1, ax2) = plt.subplots(1, 2)
    ax1.set_title('Original')
    ax2.set_title('Saliency Map')
    if (testIMG.rgb):
        ax1.imshow(testIMG.patched)
    else:
        testIMG.modified.astype(int)
Exemple #5
0
    # Generate Gamma Kernel
    # k = np.array([1, 26, 1, 25, 1, 19], dtype=float)
    # mu = np.array([2, 2, 1, 1, 0.5, 0.5], dtype=float)

    k = np.array([1, 20, 1, 30, 1, 40], dtype=float)
    mu = np.array([2, 2, 2, 2, 2, 2], dtype=float)
    kernel = foac.gamma_kernel(test_image, mask_size=(40, 40), k=k, mu=mu)

    # Generate Saliency Map
    start = time.time()
    foac.convolution(test_image, kernel, foveation_prior)
    stop = time.time()
    print(f"Salience Map Generation: {stop - start} seconds")

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(test_image, rank_count=5, bbox_size=(80, 80))

    # %% Plot Results
    test_image.plot_original_map()
    test_image.plot_modified_map
    test_image.plot_saliency_map()
    test_image.plot_ground_truth()
    # test_image.draw_image_patches(bbt=2)
    # for i in range(len(test_image.patched_sequence)):
    #     test_image.display_map(test_image.patched_sequence[i], f"{i}")
    # test_image.plot_patched_map()

    # %% Evaluate Results

    # # Precision-Recall (PR) Test
    # ap_score, f_score = foa_precision_recall_curve(test_image, plot=True)
        frame += 1
        image_name = str(frame) + ext
        image_curr = foai.ImageObject(image, fc=frame)

        # Generate Saliency Map with Gamma Filter
        foac.convolution(image_curr, kernel, prior)

        if (frame % 100 == 0):
            stop = time.time()
            print("Salience Map Gen ", frame, ": ", stop - start, " seconds")
            start = time.time()

        # Bound and Rank the most Salient Regions of Saliency Map
#        image_curr.salience_map = np.subtract(image_curr.salience_map, image_prev.salience_map)
#        image_curr.salience_map *= (image_curr.salience_map > 0.12)
        foas.salience_scan(image_curr)

        # Bounding Box images
        image_curr.draw_image_patches(salmap=False)
        image_curr.save_image_patches()
        save_image(image_curr.salience_map * 255, dir_path + "salience/",
                   image_name)
        save_image(image_curr.patched, dir_path + "bounding_box/", image_name)

        # Create combined image
        img1 = Image.open(dir_path + "salience/" + image_name)
        img2 = Image.open(dir_path + "bounding_box/" + image_name)
        result = Image.new('RGB', (2 * width, height))
        result.paste(im=img1, box=(0, 0))
        result.paste(im=img2, box=(width, 0))
        #        save_image(cv2.cvtColor(np.array(result), cv2.COLOR_BGR2RGB),
# %% Generate Saliency Map

    # Generate Gaussian Blur Prior - Time ~0.0020006
    foveation_prior = foac.matlab_style_gauss2D(test_image.modified.shape, 300)

    # Generate Gamma Kernel
    kernel = foac.gamma_kernel(test_image)

    # Generate Saliency Map
    start = time.time()
    foac.convolution(test_image, kernel, foveation_prior)
    stop = time.time()
    print("Salience Map Generation: ", stop - start, " seconds")

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(test_image, rankCount=6)

# %% Plot Results

    # Plot Bounding Box Patches
    test_image.draw_image_patches()

    # Create a figure with 2 subplots
    fig, (ax1, ax2) = plt.subplots(1, 2)
    ax1.set_title('Original')
    ax2.set_title('Saliency Map')
    if (test_image.rgb):
        ax1.imshow(test_image.patched)
    else:
        test_image.modified.astype(int)
        ax1.imshow(test_image.modified)
Exemple #8
0
    # %% Generate Saliency Map

    # Generate Gaussian Blur Prior - Time ~0.0020006
    foveation_prior = foac.matlab_style_gauss2D(test_image.modified.shape, 300)

    # Generate Gamma Kernel
    kernel = foac.gamma_kernel(test_image)

    # Generate Saliency Map
    start = time.time()
    foac.convolution(test_image, kernel, foveation_prior)
    stop = time.time()
    print(f"Salience Map Generation: {stop - start} seconds")

    # Bound and Rank the most Salient Regions of Saliency Map
    foas.salience_scan(test_image, rank_count=3)

    # %% Display Results

    # test_image.plot_original_map()
    # test_image.plot_saliency_map()
    # # Plot Bounding Box Patches
    test_image.draw_image_patches()
    # for i in range(len(test_image.patched_sequence)):
    #     test_image.display_map(test_image.patched_sequence[i], f"{i}")
    # test_image.plot_patched_map()

    # omap = test_image.original
    # smap = test_image.salience_map
    # smap = 255 * smap
    # smap = smap.astype(np.uint8)