I have implemented some code that allows me to estimate the center of distortion for an image along with a distortion parameter that attempts to remove any radial distortion present in the image. It is modelled after the 1 parameter division model:
xu = xd / (1 + K1 * r^2)
yu = yd / (1 + K1 * r^2)
I am wondering what the best way is to process this transform as fast as possible. I was thinking there should be a way to use numpy vectorization to create a mapping for a given image that I can use to perform the undistortion procedure. I have experience with OpenCV (undistort(), initUndistortRectifyMap(), etc.), however, these methods require an estimate of the camera focal properties (fx, fy
) which I do not have.
I could implement a nested for loop structure to calculate all of the undistorted destinations for a given input image size, however, this would be very inefficient. Is there an approach I can take with numpy to build this mapping?
Here is how I transform a single point from the distorted state to the undistorted state.
def get_undistorted(pd, dc, k): xd, yd = pd dcx, dcy = dc r2 = (dcx - xd)**2 + (dcy - yd)**2 xu = dcx + (xd - dcx)/(1 + k*r2) yu = dcy + (yd - dcy)/(1 + k*r2) return xu, yu