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