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
Ejemplo n.º 2
0
    def __init__(self, cnn_layers=None, fc_layers=None):
        super(Model, self).__init__()

        # Network layer initialization
        self.cnn_layers = cnn_layers
        self.fc_layers = fc_layers

        # Generate Gaussian Blur Prior - Time ~0.0020006
        self.prior = foac.matlab_style_gauss2D((60, 60), 300)

        # Generate Gamma Kernel
        k = np.array([1, 9], dtype=float)
        mu = np.array([0.2, 0.5], dtype=float)
        self.kernel = foac.gamma_kernel(mask_size=(14, 14), k=k, mu=mu)
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()
Ejemplo n.º 4
0
    mario = foai.imageObject(file)
    file = "./AIM/eyetrackingdata/original_images/22.jpg"
    banana = foai.imageObject(file)
    file = "./AIM/eyetrackingdata/original_images/120.jpg"
    corner = foai.imageObject(file)

    # Test Image
    testIMG = mario

    # %% 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()
Ejemplo n.º 5
0
    # Test Image
    test_image = corner
    test_image.ground_truth = np.array(gt_corner, dtype=np.float64)

    # %% Generate Saliency Map

    # 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, 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()
    success, image = movie.read()
    print("FIRST READ SUCCESS: ", success)

    # Get image dimensions: Mario - 224x256x3
    height, width, channels = image.shape
    print("H: ", height, "W: ", width, "C: ", channels)
    start = time.time()

    # Generate Gaussian Blur Prior - Time ~0.0020006
    prior = foac.matlab_style_gauss2D(image.shape, 300)

    # Generate Gamma Kernel
    image_curr = foai.ImageObject(image, fc=frame)
    image_prev = image_curr
    image_prev.salience_map = np.zeros(image_prev.original.shape[:-1])
    kernel = foac.gamma_kernel(image_curr)

    # Step through each movie frame
    while success:
        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()
    mario = foai.ImageObject(file)
    file = "./AIM/eyetrackingdata/original_images/22.jpg"
    banana = foai.ImageObject(file)
    file = "./AIM/eyetrackingdata/original_images/120.jpg"
    corner = foai.ImageObject(file)

    # Test Image
    test_image = mario

# %% 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()