def maximum_noise_plot(): ''' Generates a plot showing the effectiveness of the Loopy BP algorithm for varying mu values, used in the write-up. ''' disk_fp = image_processing.generate_disk(100, 40) original_image = Image(disk_fp) FLIP_PROBS = [.005, .01, .05, .1, .2, .3, .4, .5] noises = [] for prob in FLIP_PROBS: noisy_fp = image_processing.noisify(disk_fp, prob) # plt.imshow(np.genfromtxt(noisy_fp), cmap='Greys') # plt.show() noisy_image = Image(noisy_fp) denoised_fp = loopy_bp(noisy_image, THETA) denoised_image = Image(denoised_fp) fraction_noise = original_image.percent_different(denoised_image) print fraction_noise noises.append(fraction_noise) plt.plot(FLIP_PROBS, noises) plt.plot(FLIP_PROBS, FLIP_PROBS) plt.xlabel("Mu value (flip probability)") plt.ylabel("Fraction noise") plt.show()
def find_optimal_theta(): ''' Produces the plot finding the optimal Theta, used in the write-up. I found that the optimal thetas were the highest, and I decided to use 0.9 for the bulk of my analysis. ''' THETAS = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.999] FLIP_PROBS = [0.005, 0.05, 0.25, 0.5] noises = [] disk_fp = image_processing.generate_disk(100, 40) original_image = Image(disk_fp) noisy_fps = [] for prob in FLIP_PROBS: noisy_fps.append(image_processing.noisify(disk_fp, prob)) for noisy_image_fp in noisy_fps: noise = [] for theta in THETAS: print noisy_image_fp, theta noisy_image = Image(noisy_image_fp) loopy_bp(noisy_image, theta) denoised_image = Image(noisy_image.file_path + "_denoised") percent_noise = original_image.percent_different(denoised_image) noise.append(percent_noise) os.remove(noisy_image.file_path + "_denoised") noises.append(noise) for noise in noises: plt.plot(THETAS, noise) plt.xlabel("Theta") plt.ylabel("Fraction noise") plt.show()
def print_images(): ''' Prints all the images shown in the write-up.''' # Circle with radius 40 disk_fp = image_processing.generate_disk(100, 40) show_image(disk_fp) # Circle with mu = 0.01 noisy_fp = image_processing.noisify(disk_fp, 0.01) show_image(noisy_fp) # Circle cleaned up, mu = 0.01 noisy_image = Image(noisy_fp) denoised_fp = loopy_bp(noisy_image, THETA) show_image(denoised_fp) # Circle with mu = 0.1 noisy_fp = image_processing.noisify(disk_fp, 0.1) show_image(noisy_fp) # Circle cleaned up, mu = 0.1 noisy_image = Image(noisy_fp) denoised_fp = loopy_bp(noisy_image, THETA) show_image(denoised_fp) # Square, 60 x 60 square_fp = image_processing.generate_square(100, 60, 50) show_image(square_fp) # Square with mu = 0.01 noisy_fp = image_processing.noisify(square_fp, 0.01) show_image(noisy_fp) # Square cleaned up, mu = 0.01 noisy_image = Image(noisy_fp) denoised_fp = loopy_bp(noisy_image, THETA) show_image(denoised_fp) # Equals Sign equals_fp = image_processing.generate_equalsign() show_image(equals_fp) # Equals with mu = 0.01 noisy_fp = image_processing.noisify(equals_fp, 0.01) show_image(noisy_fp) # Square cleaned up, mu = 0.01 noisy_image = Image(noisy_fp) denoised_fp = loopy_bp(noisy_image, THETA) show_image(denoised_fp)