def part_2a(ps5_obj, save_imgs=True): part_1c(ps5_obj, False) # sets up arrays object from last part # Todo: Define size values to be used in ps5.get_keypoints size = {"trans_a": 10., "trans_b": 10., "sim_a": 10., "sim_b": 10.} # You can leave these values to 0 octave = {"trans_a": 0, "trans_b": 0, "sim_a": 0, "sim_b": 0} ps5_obj.compute_angles() ps5_obj.create_keypoints(size, octave) keypoints = ps5_obj.get_keypoints() r_maps = ps5_obj.get_r_maps() if save_imgs: trans_a_out = draw_keypoints(keypoints["trans_a"], r_maps["trans_a"]) trans_b_out = draw_keypoints(keypoints["trans_b"], r_maps["trans_b"]) sim_a_out = draw_keypoints(keypoints["sim_a"], r_maps["sim_a"]) sim_b_out = draw_keypoints(keypoints["sim_b"], r_maps["sim_b"]) trans_a_b_out = ps5.make_image_pair(trans_a_out, trans_b_out) sim_a_b_out = ps5.make_image_pair(sim_a_out, sim_b_out) imwrite("ps5-2-a-1.png", trans_a_b_out) imwrite("ps5-2-a-2.png", sim_a_b_out)
def part_1a(ps5_obj, save_imgs=True): gradients = ps5_obj.get_gradients_a() trans_a_x, trans_a_y = gradients["t_x"], gradients["t_y"] sim_a_x, sim_a_y = gradients["s_x"], gradients["s_y"] if save_imgs: trans_a_pair = ps5.make_image_pair(trans_a_x, trans_a_y) imwrite("ps5-1-a-1.png", trans_a_pair) sim_a_pair = ps5.make_image_pair(sim_a_x, sim_a_y) imwrite("ps5-1-a-2.png", sim_a_pair) return {"t_x": trans_a_x, "t_y": trans_a_y, "s_x": sim_a_x, "s_y": sim_a_y}
def part_3a(ps5_obj): part_2b(ps5_obj, False) # Sets up arrays object from part 2b images = ps5_obj.get_input_images() k_pts = ps5_obj.get_keypoints() matches = ps5_obj.get_matches() threshold = 15. # Todo: Define a threshold value. translation, good_matches = ps5.compute_translation_RANSAC( k_pts["trans_a"], k_pts["trans_b"], matches["trans"], threshold) print '3a: Translation vector: \n', translation trans_pair = ps5.make_image_pair(images["trans_a"], images["trans_b"]) trans_pair = draw_consensus_set(good_matches, trans_pair, images["trans_a"].shape) cv2.imwrite(os.path.join(output_dir, "ps5-3-a-1.png"), trans_pair)
def part_3c(ps5_obj, save_imgs=True): part_2b(ps5_obj, False) # Sets up arrays object from part 2b images = ps5_obj.get_input_images() k_pts = ps5_obj.get_keypoints() matches = ps5_obj.get_matches() threshold = 15. # Todo: Define a threshold value. similarity_affine, sim_aff_good_matches = ps5.compute_affine_RANSAC( k_pts["sim_a"], k_pts["sim_b"], matches["sim"], threshold) if save_imgs: print '3c: Transform Matrix for the best set: \n', similarity_affine sim_aff_pair = ps5.make_image_pair(images["sim_a"], images["sim_b"]) sim_aff_pair = draw_consensus_set(sim_aff_good_matches, sim_aff_pair, images["sim_a"].shape) cv2.imwrite(os.path.join(output_dir, "ps5-3-c-1.png"), sim_aff_pair) return similarity_affine