DOI-USGS / usgscsm

This repository stores USGS Community Sensor Model (CSM) camera models
Other
26 stars 33 forks source link

Issues with lens distortion computation #488

Open oleg-alexandrov opened 1 month ago

oleg-alexandrov commented 1 month ago

This is similar to https://github.com/DOI-USGS/usgscsm/issues/461, but applies to the cahvor distortion model.

For cahvor distortion, the formula (https://github.com/DOI-USGS/usgscsm/blob/main/src/Distortion.cpp#L325) is:

 double rr = shiftedDx * shiftedDx + shiftedDy * shiftedDy;

  if (rr > tolerance)
  {
    double dr = opticalDistCoeffs[0] +
                (rr * (opticalDistCoeffs[1] + rr * opticalDistCoeffs[2]));

    ux = shiftedDx * (1.0 - dr);
    uy = shiftedDy * (1.0 - dr);
    ux += opticalDistCoeffs[3];
    uy += opticalDistCoeffs[4];
  }
}
break;

When rr is smaller than tolerance, the undistortion ux and uy is assumed to be equal to input distorted values, which is wrong.

Need to add the optical shifts given by opticalDistCoeffs[3] and [4] even when rr is small.

This formula should not have an if statement at all. This is a simple polynomial formula, that works for any input.

The same for cahvor undistortion, at https://github.com/DOI-USGS/usgscsm/blob/main/src/Distortion.cpp#L585

There is no need to consider a tolerance. The only division by a value is:

dx = shiftedUx / (1.0 - drOverR); dy = shiftedUy / (1.0 - drOverR);

and here it doesn't matter if we are close to the origin, as that does not make 1.0 - drOverR be equal to 0, rather, this quantity is close to 1.0.