def save_and_visualize(images, kernel_size=15, save=True): """Iterates through images and saves and prints both the original images, output orientation images, and target orientation images, in that order. Images : a list of tuples of (input_image (3x224x224), orientation_image (2x224x224), target_orientation_image (2x224x224)) """ for i, (input, output, target) in enumerate(images): check_sizes(input, output) plt.figure(figsize=(15, 5)) plt.subplot(131) plt.imshow(np.moveaxis(input, 0, 2)) ax = plt.gca() ax.set_axis_off() ax.set_title("Input") plt.subplot(132) ax2 = show_orientation_image(output) ax2.set_title("Decoded orientation") try: #if target is not None: plt.subplot(133) ax3 = show_orientation_image(target) ax3.set_title("Target orientation") except: print("Recomputing orientation image with kernel size {}".format( kernel_size)) filts = get_quadratures(kernel_size) # note that we invert to get the map target = get_orientation_map( 1 - np.mean(check_on_float_scale(input), axis=0), filts) plt.subplot(133) ax3 = show_orientation_image(target) ax3.set_title("Target orientation") plt.tight_layout() if save: plt.savefig("Decoded_test_image_{}.png".format(i)) #save just decoded png print(type(output), output.shape) output_img = convert_to_orientation_image(output) target_img = convert_to_orientation_image(target) # matplotlib.image.imsave('only_original_img_{}'.format(i), input) matplotlib.image.imsave('only_decoded_img_{}.png'.format(i), output_img) matplotlib.image.imsave('only_target_img_{}.png'.format(i), target_img) plt.show()
def gen_batch_random_curved_lines(red, green, blue, num_lines_per_img): all_inputs = list() all_targets = list() n_samples = 10000 for n in range(n_samples): image_array = np.zeros((3, 224, 224)) input = add_random_curved_lines(image_array, red, green, blue, num_lines_per_img) target = get_orientation_map(input[0], filts) all_inputs.append(input.reshape(-1)) all_targets.append(target.reshape(-1)) return all_inputs, all_targets