Thursday, January 26, 2012

Correcting Perspective Distortions

NIO, my camera assistant, was a little upset when he heard about Kodak's problems last week and wanted to help out if he could. We agreed that a blog on how the "music intervals image" was corrected might help some.

I captured the original image by just holding the camera over the book that it was in and the distortion is quite obvious. There are a number of contributing factors such as the relative position of the camera and the distortion produced by the telephoto lens.


I used the quadratic transformation method previously used for the determination of the coordinates of the Sun's image on graph paper at the time of the Summer Solstice to correct for some of the image's distortion. To find the needed transformation I obtained the pixel positions, X, of the line intersections from the original image. The positions of these intersections in the book were measured to the nearest millimeter and rescaled, X', to better match the image positions. Note that the first point which was the upper left intersection was arbitrarily chosen to coincide with that in the original image.


The transformation doesn't give interger positions which are needed for the corrected image so the 2D interpolation method was used to obtain a pixel value for the corrected image using the nearest know pixels in the original image. This was the first image posted in the blog.


As you can see there was still some barrel distortion present. I found that pre-distorting the corrected image positions before transforming to the position needed to interpolate the pixel value did a good job in straightening out the image. The distortion factor turned out to be 3%.


The result of both transformations is the image below and is the correction posted.


The 2D interpolation does a good job of preserving lettering without adding gaps that might be caused by stretching the image to fit the new pixel grid. One can see the images at full resolution by clicking on them. Also, the effects of the two-step transformation process can be better seen by rapidly switching between consecutive images in an image viewer. The first transformation appears to reposition the image and the second straightens out the lines.

Why are two transformations needed? It could be that the first gives a better fit for the center while the second works better on the edges. The second correction is nonlinear while the first involves only linear coefficients.

I don't know if you can do this in Photoshop but the process does give more useful images.

Supplemental (Jan 29): You can do perspective cropping and lens distortion corrections with Photoshop.

No comments: