Skip to content
Snippets Groups Projects
Unverified Commit 4c8ce703 authored by Oleg Alexandrov's avatar Oleg Alexandrov Committed by GitHub
Browse files

No need for tolerance check for radial distortion (#464)

* No need for tolerance check for radial distortion

* Indentation in src/Distortion.cpp
parent ce4d6a19
No related branches found
No related tags found
No related merge requests found
...@@ -94,13 +94,11 @@ void removeDistortion(double dx, double dy, double &ux, double &uy, ...@@ -94,13 +94,11 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
case RADIAL: { case RADIAL: {
double rr = dx * dx + dy * dy; double rr = dx * dx + dy * dy;
if (rr > tolerance) {
double dr = opticalDistCoeffs[0] + double dr = opticalDistCoeffs[0] +
(rr * (opticalDistCoeffs[1] + rr * opticalDistCoeffs[2])); (rr * (opticalDistCoeffs[1] + rr * opticalDistCoeffs[2]));
ux = dx * (1.0 - dr); ux = dx * (1.0 - dr);
uy = dy * (1.0 - dr); uy = dy * (1.0 - dr);
}
} break; } break;
// Computes undistorted focal plane (x,y) coordinates given a distorted // Computes undistorted focal plane (x,y) coordinates given a distorted
...@@ -221,7 +219,7 @@ void removeDistortion(double dx, double dy, double &ux, double &uy, ...@@ -221,7 +219,7 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
bool done; bool done;
/**************************************************************************** /****************************************************************************
* Pre-loop intializations * Pre-loop initializations
****************************************************************************/ ****************************************************************************/
r2 = dy * dy + dx * dx; r2 = dy * dy + dx * dx;
...@@ -255,7 +253,7 @@ void removeDistortion(double dx, double dy, double &ux, double &uy, ...@@ -255,7 +253,7 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
} while (!done); } while (!done);
/**************************************************************************** /****************************************************************************
* Sucess ... * Success ...
****************************************************************************/ ****************************************************************************/
ux = guess_ux; ux = guess_ux;
...@@ -327,14 +325,13 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, ...@@ -327,14 +325,13 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
dy = uy; dy = uy;
switch (distortionType) { switch (distortionType) {
// Compute undistorted focal plane coordinate given a distorted // Compute distorted focal plane coordinate given undistorted
// focal plane coordinate. This case works by iteratively adding distortion // focal plane coordinates. This case works by iteratively adding distortion
// until the new distorted point, r, undistorts to within a tolerance of the // until the new distorted point, r, undistorts to within a tolerance of the
// original point, rp. // original point, rp.
case RADIAL: { case RADIAL: {
double rp2 = (ux * ux) + (uy * uy); double rp2 = (ux * ux) + (uy * uy);
if (rp2 > tolerance) {
double rp = sqrt(rp2); double rp = sqrt(rp2);
// Compute first fractional distortion using rp // Compute first fractional distortion using rp
double drOverR = double drOverR =
...@@ -372,7 +369,7 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, ...@@ -372,7 +369,7 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
dx = ux / (1.0 - drOverR); dx = ux / (1.0 - drOverR);
dy = uy / (1.0 - drOverR); dy = uy / (1.0 - drOverR);
}
} break; } break;
case TRANSVERSE: { case TRANSVERSE: {
computeTransverseDistortion(ux, uy, dx, dy, opticalDistCoeffs); computeTransverseDistortion(ux, uy, dx, dy, opticalDistCoeffs);
...@@ -468,7 +465,7 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, ...@@ -468,7 +465,7 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
// The LRO LROC NAC distortion model uses an iterative approach to go from // The LRO LROC NAC distortion model uses an iterative approach to go from
// undistorted x,y to distorted x,y // undistorted x,y to distorted x,y
// Algorithum adapted from ISIS3 LRONarrowAngleDistortionMap.cpp // Algorithm adapted from ISIS3 LRONarrowAngleDistortionMap.cpp
case LROLROCNAC: { case LROLROCNAC: {
double yt = uy; double yt = uy;
...@@ -491,9 +488,9 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, ...@@ -491,9 +488,9 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
double dk1 = opticalDistCoeffs[0]; double dk1 = opticalDistCoeffs[0];
// Owing to the odd distotion model employed in this senser if |y| is > // Owing to the odd distortion model employed in this sensor if |y| is >
// 116.881145553046 then there is no root to find. Further, the greatest // 116.881145553046 then there is no root to find. Further, the greatest
// y that any measure on the sensor will acutally distort to is less // y that any measure on the sensor will actually distort to is less
// than 20. Thus, if any distorted measure is greater that that skip the // than 20. Thus, if any distorted measure is greater that that skip the
// iterations. The points isn't in the cube, and exactly how far outside // iterations. The points isn't in the cube, and exactly how far outside
// the cube is irrelevant. Just let the camera model know its not in the // the cube is irrelevant. Just let the camera model know its not in the
......
...@@ -124,17 +124,26 @@ TEST(transverse, removeDistortion_AlternatingOnes) { ...@@ -124,17 +124,26 @@ TEST(transverse, removeDistortion_AlternatingOnes) {
EXPECT_NEAR(uy, 7.5, 1e-8); EXPECT_NEAR(uy, 7.5, 1e-8);
} }
TEST(Radial, testRemoveDistortion) { TEST(Radial, testUndistortDistort) {
csm::ImageCoord imagePt(0.0, 4.0);
double ux, uy; // Distorted pixel
std::vector<double> coeffs = {0, 0, 0}; csm::ImageCoord imagePt(0.0, 1e-1);
// Undistort
double ux, uy;
std::vector<double> coeffs = {0.03, 0.00001, 0.000004};
double tolerance = 1e-2;
removeDistortion(imagePt.samp, imagePt.line, ux, uy, coeffs, removeDistortion(imagePt.samp, imagePt.line, ux, uy, coeffs,
DistortionType::RADIAL); DistortionType::RADIAL, tolerance);
EXPECT_NEAR(ux, 4, 1e-8); // Distort back
EXPECT_NEAR(uy, 0, 1e-8); double desiredPrecision = 1e-6;
double dx, dy;
applyDistortion(ux, uy, dx, dy, coeffs,
DistortionType::RADIAL, desiredPrecision, tolerance);
EXPECT_NEAR(dx, imagePt.samp, 1e-8);
EXPECT_NEAR(dy, imagePt.line, 1e-8);
} }
// If coeffs are 0 then this will have the same result as removeDistortion // If coeffs are 0 then this will have the same result as removeDistortion
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment