def test_find_cod_fine(self): x_cod, y_cod = proc.find_cod_coarse(self.list_hor_dlines, self.list_ver_dlines) x_cod, y_cod = proc.find_cod_fine(self.list_hor_dlines, self.list_ver_dlines, x_cod, y_cod, self.dot_dist) self.assertTrue(isinstance(x_cod, float) and isinstance(y_cod, float))
def test_calc_coef_fordward(self): x_cod, y_cod = proc.find_cod_coarse(self.list_hor_dlines, self.list_ver_dlines) list_fact = proc.calc_coef_forward(self.list_hor_dlines, self.list_ver_dlines, x_cod, y_cod, 2) error1 = np.abs((list_fact[0] - self.list_fact[0]) / self.list_fact[0]) error2 = np.abs((list_fact[1] + self.list_fact[1]) / self.list_fact[1]) self.assertTrue(error1 < 0.1 and error2 < 0.2)
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
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)) # Check the correction results: # Apply correction to the lines of points list_uhor_lines = post.unwarp_line_backward(list_hor_lines, xcenter, ycenter, list_fact) list_uver_lines = post.unwarp_line_backward(list_ver_lines, xcenter, ycenter, list_fact) # Calculate the residual of the unwarpped points. list_hor_data = post.calc_residual_hor(list_uhor_lines, xcenter, ycenter)
def test_find_cod_coarse(self): x_cod, y_cod = proc.find_cod_coarse(self.list_hor_dlines, self.list_ver_dlines) self.assertTrue((np.abs(x_cod - self.x0) < self.dot_dist) and (np.abs(y_cod - self.y0) < self.dot_dist))