def test_remove_residual_dots_hor(self): mat1 = np.copy(self.mat_dots) mat1[9:11, 42:44] = np.float32(1.0) list_lines = prep.group_dots_hor_lines(mat1, 0.0, 10.0, ratio=0.3, num_dot_miss=3, accepted_ratio=0.8) num1 = np.sum(np.asarray([len(line) for line in list_lines])) list_lines2 = prep.remove_residual_dots_hor(list_lines, 0.0, 1.5) num2 = np.sum(np.asarray([len(line) for line in list_lines2])) self.assertTrue(num1 == num2 + 1)
def calc_distor_coef(mat, num_coef, perspective=False): # Pre-processing mat1 = prep.binarization(mat) (dot_size, dot_dist) = prep.calc_size_distance(mat1) mat1 = prep.select_dots_based_size(mat1, dot_size) mat1 = prep.select_dots_based_ratio(mat1) hor_slope = prep.calc_hor_slope(mat1) ver_slope = prep.calc_ver_slope(mat1) list_hor_lines = prep.group_dots_hor_lines(mat1, hor_slope, dot_dist) list_ver_lines = prep.group_dots_ver_lines(mat1, ver_slope, dot_dist) list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, hor_slope) list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, ver_slope) if perspective is True: try: list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola( list_hor_lines, list_ver_lines, perspective=perspective) except AttributeError: raise ValueError("Perspective correction only available " "from Discorpy 1.4!!!") # Processing (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) return xcenter, ycenter, list_fact
# Group points into lines list_hor_lines = prep.group_dots_hor_lines(list_points_hor_lines, slope_hor, dist_hor, ratio=0.1, num_dot_miss=2, accepted_ratio=0.8) list_ver_lines = prep.group_dots_ver_lines(list_points_ver_lines, slope_ver, 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.
# Remove non-dot objects mat1 = prep.select_dots_based_size(mat1, dot_size) # Remove non-elliptical objects mat1 = prep.select_dots_based_ratio(mat1) io.save_image(output_base + "/segmented_dots.jpg", mat1) # Calculate the slopes of horizontal lines and vertical lines. hor_slope = prep.calc_hor_slope(mat1) ver_slope = prep.calc_ver_slope(mat1) print("Horizontal slope: {0}. Vertical slope: {1}".format(hor_slope, ver_slope)) # Group points to horizontal lines list_hor_lines = prep.group_dots_hor_lines(mat1, hor_slope, dot_dist) # Group points to vertical lines list_ver_lines = prep.group_dots_ver_lines(mat1, ver_slope, dot_dist) # Optional: remove horizontal outliners list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, hor_slope) # Optional: remove vertical outliners list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, ver_slope) # 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) # Check residual of dots on lines 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)