Correct image for distortion by external lens

Hi All

I am capturing images of an object inside an acrylic cylinder filled with oil (simple plan view sketch below). Due to the refractive index mismatch the cylinder acts as a lens and distorts my images horizontally.

My setup is in a controlled environment so I can define the position of the camera, cylinder and object fairly accurately. Consequently, I can calculate the distorted (a) and undistorted (a’) image point for a given point A on the object using ray tracing. Currently I am using findHomography to calculate a homography matrix from the distorted (a) and undistorted (a’) points. I then use this matrix and warpPerspective to correct for the distortion.

Is this the most efficient way to do it? Or should I be looking at something in the line of calibrateCamera? If so, how should I go about it as I only have one set of points on the image and object planes.


1 Like

I doubt homographies can model this type of distortion. homographies are for plane-to-plane projections. this however involves all kinds of trigonometry.

something like calibrateCamera might be needed. ordinarily, distortion for lenses is modeled as a polynomial over the radius, and then used to correct the picture (“undistortion”, maybe using cv::remap). you might need something along those lines.

you said you can raytrace this. that’s good for exploring the situation.

I’ll assume that you care about the surface of the solid black cylinder.

assuming you have enough control over the ray tracing, remove all lighting and media effects, and apply to the cylinder a dummy “texture” with given (u,v) coordinates (or equivalent mechanism), and have that mapped to your image plane.

you might need the inverse of that, i.e. given coordinates on the cylinder, where on the image plane that point is mapped to, so you can map an actual image back to the cylinder.

thanks to the lens effect of the oil cylinder, I guess this will introduce blur… or not, if you stick with simple raytracing. I don’t have a good grasp of the situation.

Thanks for the suggestions! As a check I used the homography matrix to back-calculate the calibration points, and the error was quite significant.

I made a mistake in the sketch, I am actually taking a photo of a section through the cylinder. This section is perpendicular to the camera. It seems that the best solution for me is to use the simple (analytical) raytracing to find the distorted and undistorted image points for a grid over the section. Then I will fit a polynomial to these points and use the fitted surface to populate cv::remap as you suggested.