Beispiel #1
0
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)
list_ver_data = post.calc_residual_ver(list_uver_lines, xcenter, ycenter)
# Save the results for checking
io.save_plot_image(output_base + "/unwarpped_horizontal_lines.png",
                   list_uhor_lines, height, width)
Beispiel #2
0
 def test_load_metadata_txt(self):
     file_path = "data/coef1.txt"
     losa.save_metadata_txt(file_path, 31.0, 32.0, [1.0, 0.0])
     (x, y, facts) = losa.load_metadata_txt(file_path)
     self.assertTrue(((x == 31.0) and (y == 32.0)) and facts == [1.0, 0.0])
Beispiel #3
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)
io.save_image(output_base + "/corrected_image.tif", corrected_mat)
io.save_metadata_txt(output_base + "/coefficients.txt", xcenter, ycenter,
                     list_fact)
io.save_image(output_base + "/difference.tif", mat0 - corrected_mat)

# Check the correction results
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)
list_hor_data = post.calc_residual_hor(list_uhor_lines, xcenter, ycenter)
list_ver_data = post.calc_residual_ver(list_uver_lines, xcenter, ycenter)
io.save_residual_plot(output_base + "/residual_horizontal_points_after.png",
                      list_hor_data, height, width)
io.save_residual_plot(output_base + "/residual_vertical_points_after.png",
                      list_ver_data, height, width)
print("!!! Done !!!!")
Beispiel #4
0
 def test_save_metadata_txt(self):
     file_path = "data/coef.txt"
     losa.save_metadata_txt(file_path, 31, 32, (1.0, 0.0))
     self.assertTrue(os.path.isfile(file_path))
Beispiel #5
0
print("8 ---> Calculate distortion coefficients")
# Calculate distortion coefficients using the backward-from-forward model
list_ffact, list_bfact = proc.calc_coef_backward_from_forward(
    list_hor_lines, list_ver_lines, xcenter, ycenter, poly_order)

# # Calculate distortion coefficients using the backward model
# list_bfact = proc.calc_coef_backward(
#     list_hor_lines, list_ver_lines, xcenter, ycenter, poly_order)

# Apply distortion correction
print("9 ---> Apply distortion correction")
corrected_mat = post.unwarp_image_backward(mat0, xcenter, ycenter, list_bfact)
io.save_image(output_base + "/corrected_image.tif", corrected_mat)
io.save_image(output_base + "/original_image.tif", mat0)
io.save_metadata_txt(output_base + "/distortion_coefficients_bw.txt", xcenter,
                     ycenter, list_bfact)
# Check the correction results
print("10---> Evaluate the correction results")
list_uhor_lines = post.unwarp_line_backward(list_hor_lines, xcenter, ycenter,
                                            list_bfact)
list_uver_lines = post.unwarp_line_backward(list_ver_lines, xcenter, ycenter,
                                            list_bfact)
io.save_plot_image(output_base + "/horizontal_dots_unwarped.png",
                   list_uhor_lines, height, width)
io.save_plot_image(output_base + "/vertical_dots_unwarped.png",
                   list_uver_lines, height, width)
list_hor_data = post.calc_residual_hor(list_uhor_lines, xcenter, ycenter)
list_ver_data = post.calc_residual_ver(list_uver_lines, xcenter, ycenter)
io.save_residual_plot(output_base + "/residual_hor_after_correction.png",
                      list_hor_data, height, width)
io.save_residual_plot(output_base + "/residual_ver_after_correction.png",