def test_save_residual_plot(self): ver = sys.version[:3] check = True if ver != "2.7": file_path = "data/plot1.png" list_data = np.ones((64, 2), dtype=np.float32) list_data[:, 0] = 0.5 * np.random.rand(64) list_data[:, 1] = np.arange(64) losa.save_residual_plot(file_path, list_data, 64, 64, dpi=100) check = os.path.isfile(file_path) self.assertTrue(check)
dist_ver, ratio=0.1, num_dot_miss=2, accepted_ratio=0.8) # Remove residual dots list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, slope_hor, 2.0) list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, slope_ver, 2.0) # Save output for checking io.save_plot_image(output_base + "/horizontal_lines.png", list_hor_lines, height, width) io.save_plot_image(output_base + "/vertical_lines.png", list_ver_lines, height, width) list_hor_data = post.calc_residual_hor(list_hor_lines, 0.0, 0.0) list_ver_data = post.calc_residual_ver(list_ver_lines, 0.0, 0.0) io.save_residual_plot(output_base + "/hor_residual_before_correction.png", list_hor_data, height, width) io.save_residual_plot(output_base + "/ver_residual_before_correction.png", list_ver_data, height, width) # Regenerate grid points after correcting the perspective effect. list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola( list_hor_lines, list_ver_lines, perspective=True) # Calculate parameters of the radial correction model (xcenter, ycenter) = proc.find_cod_coarse(list_hor_lines, list_ver_lines) list_fact = proc.calc_coef_backward(list_hor_lines, list_ver_lines, xcenter, ycenter, num_coef) io.save_metadata_txt(output_base + "/coefficients_radial_distortion.txt", xcenter, ycenter, list_fact) print("X-center: {0}. Y-center: {1}".format(xcenter, ycenter)) print("Coefficients: {0}".format(list_fact))
# Optional: remove residual dots list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, slope_hor, 2.0) list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, slope_ver, 2.0) print("5-> Correct perspective effect !!!!") # Optional: correct perspective effect. list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola( list_hor_lines, list_ver_lines, perspective=True) io.save_plot_image(output_base + "/hor_lines.png", list_hor_lines, height, width) io.save_plot_image(output_base + "/ver_lines.png", list_ver_lines, height, width) # Check if the distortion is significant. list_hor_data = post.calc_residual_hor(list_hor_lines, 0.0, 0.0) io.save_residual_plot(output_base + "/residual_horizontal_points_before.png", list_hor_data, height, width) list_ver_data = post.calc_residual_ver(list_ver_lines, 0.0, 0.0) io.save_residual_plot(output_base + "/residual_vertical_points_before.png", list_ver_data, height, width) print("6-> Calculate the centre of distortion !!!!") (xcenter, ycenter) = proc.find_cod_coarse(list_hor_lines, list_ver_lines) print(" X-center: {0}, Y-center: {1}".format(xcenter, ycenter)) print("7-> Calculate radial distortion coefficients !!!!") list_fact = proc.calc_coef_backward(list_hor_lines, list_ver_lines, xcenter, ycenter, num_coef) # Output print("8-> Apply correction to image !!!!") corrected_mat = post.unwarp_image_backward(mat0, xcenter, ycenter, list_fact)
hor_slope, residual=2.0) list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, ver_slope, residual=2.0) io.save_plot_image(output_base + "/horizontal_dots_refined.png", list_hor_lines, height, width) io.save_plot_image(output_base + "/vertical_dots_refined.png", list_ver_lines, height, width) time_stop = timeit.default_timer() print("Group dots into horizontal lines and vertical lines in {}" " second!".format(time_stop - time_start)) # Optional step: check if the distortion is significant. list_hor_data = post.calc_residual_hor(list_hor_lines, 0.0, 0.0) io.save_residual_plot(output_base + "/residual_horizontal_dots_before.png", list_hor_data, height, width) list_ver_data = post.calc_residual_ver(list_ver_lines, 0.0, 0.0) io.save_residual_plot(output_base + "/residual_vertical_dots_before.png", list_ver_data, height, width) check1 = post.check_distortion(list_hor_data) check2 = post.check_distortion(list_ver_data) if (not check1) and (not check2): print("!!! Distortion is not significant !!!") # Optional: correct perspective effect. Only available from Discorpy 1.4 if perspective is True: try: list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola( list_hor_lines, list_ver_lines, perspective=True) except AttributeError: raise ValueError(