ME 453/553 – Digital Image Distortion Correction Brian K. Bay – OSU School of Mechanical, Industrial & Manufacturing Engineering Approach: Map a location within a regular rectangular region to a distorted rectangular region, then return a value associated with the mapped location. map the location … ° … return a value Among other uses this is an approach for distortion correction of images. If you setup a digital camera for measurements within a plane, you need undistorted images (left), but at some level of precision the original images are always irregular (right). We need a convenient and flexible technique for calibrating the measurement plane. One approach is to create a template for the undistorted image (a blank pixel array), and then fill-in this template using information from the distorted image. For any given location within the template (open circle), if you identify an appropriate location within the distorted image (open square) you can get a pixel value from there. So the basic process is: map the location, return a value. The following illustrations will guide the equation development. u0x, u0y u1x, u1y d0x, d0y d1x, d1y d2x, d2y u2x, u2y corrected image domain u3x, u3y calibration target domain d3x, d3y Calibration The left illustration shows four corners (u0, u1, u2, u3) of an undistorted region within a new blank image (dashed line.) This image will ultimately be filled through the map … return process. The right illustration shows corresponding points (d0, d1, d2, d3) of a distorted region within an image. Points in the distorted image are actual markers placed on a calibration target in a controlled way, with location and spacing known to a high degree of precision. Markers do not appear at the expected locations in the image due to irregularities (camera alignment imprecision, lens distortions, etc.) in the optical system. The first step is to choose a basis for the mapping process. A bilinear polynomial is used here, although there are many other options. The basis defines equations for the x,y coordinates of an arbitrary location within the distorted image (dx, dy) that corresponds to an x,y location within the undistorted image (ux, uy): dx c 0 ux c1uy c 2 ux uy c 3 dy c 4 ux c 5 uy c 6 ux uy c 7 Eq. 1 If we know a location within the undeformed space (ux, uy), we can calculate a corresponding location within the deformed space (dx, dy). But clearly we need the set of eight mapping coefficients (c0, c1, c2, c3, c4, c5, c6, c7). To find the eight mapping coefficients we need eight equations, and these equations can be developed with knowledge of the vertices (“corners”) in the undeformed and deformed spaces. This is the role of the calibration target. We know what the target is supposed to look like in an image (where the u0…u3 points ought to be), and we can measure where they actually are (image the calibration target, threshold the markers, find their centers to produce d0…d3 locations.) This set of equations expresses mapping of the four vertex locations: d0x u0x d0y 0 d1x u1x d1y 0 d2x u2x d2y 0 d3x u3x d3y 0 u0y u0x u0y 1 0 0 0 0 u1y 0 u1x u1y 0 u0x 1 0 u0y 0 u0x u0y 0 0 u2y 0 u2x u2y 0 1 u1x 0 u1y 0 u1x u1y 0 0 u3y 0 u3x u3y 0 u2x 1 0 u2y 0 u2x u2y 0 0 0 0 u3x u3y u3x u3y 0c 0 1c1 0c 2 1 c 3 0c 4 1c 5 0c 6 1 c 7 Eq. 2 or simply d uc. We can invert this system to find the mapping coefficients: c u d. Now any location within the corrected image domain can be mapped 1 to the distorted image by using Equation 1. Image Correction Once the calibration process is complete (determination of mapping coefficients) any image collected by the system can be corrected for distortion. A good initial check is to correct the calibration target image and verify that it is in fact undistorted. But the important point is that any image can be subjected to the map…return process with mapping controlled by the coefficients determined during calibration and return based on content of the original image. Software rasters through pixels of the corrected image from top-left to bottom-right (1, 2, 3, … , N) mapping and returning values from the original image. Since a mapped location is generally not at the precise center of an actual pixel in the original image, some means of deciding what value to return is required. A nearest pixel approach is simple and fast, but interpolation between pixel values improves smoothness of the corrected image. 1,2,3,… 1,2,3,… distortion corrected image N original image N Perspective, Lens Aberration, and Combined Distortions The most obvious problem encountered in using a digital camera as a measurement tool is alignment of the imaging plane (the CCD surface inside the camera) with the measurement plane. It is impossible to achieve perfect alignment with physical positioning adjustments, although it is best if you get good physical alignment. To correct for the perspective distortion that results, a single mapped region of the type described above is suitable. However, there are always other more complex distortions in an imaging system. Optical lenses all have aberrations that distort the image in ways that a single bilinear polynomial will not adequately correct. A variety of methods have been developed to manage specific types of common lens aberrations, but it is difficult to accurately characterize a lens, and lens distortion always occurs together with some degree of perspective shift. Both can be effectively managed together by simply creating many bilinear mapping regions instead of one. Each region has its own set of calibration coefficients and is mapped independently. The software implementation is a bit more involved, but very complex distortions can be dealt with using nothing more than a target with a grid of accurately spaced dots. Perspective Distortion Single Mapped Region Lens Aberration Combined Multiple Mapped Regions