Wednesday, September 9, 2009

Activity 13 Correcting Geometric Distortion

Have you ever tried looking through one of those door peepholes, the ones that allow you to see who is knocking on your door? I, myself, have only tried it ones when I visited my cousin who lived in a hotel and the door of their room had one. Anyway, for those of you who have tried using one, I am sure that you have also noticed that the image you see through it is highly distorted. This geometric distortion is similar to that found in some cameras (in a much lower degree) and other instruments that use spherical lenses. Basically geometric distortion results from the varying magnification as the distance from the optical axis increases. The two most common forms of this optical abberation is the barrel (magnification decreases farther from the optical axis) and pincushion distortion (magnification increases farther from the optical axis). In photography barrel distortion is commonly encountered when taking wide angle photos. In this activity we will be correcting geometrically distorted images numerically.
Figure 1. Example of distorted images

Our method of correcting geometric distortion involves two main steps. The first step is correcting the pixel coordinates, which refers to mapping the coordinates of the distorted image back to the ideal undistorted image. Our experience with image processing allows us to understand that the process of distortion simply involves the ideal undistorted image and a distorting transfer function such that
Equation 1

Where T is the transfer function and f and g are the undistorted and distorted images respectively. So given the distorted image we just need the transfer function to recover our ideal image. However the process to determine the transfer function requires us to have information on the undistorted image. Our method allows us to calculate the transfer function using only vertices of polygons or regularly occurring patterns present in our image.

Figure 2

Consider figure 2 above where we show an undistorted and distorted polygon/grid. assuming that the area of the polygon is not to large we can approximate the transformation as
Equation 2

The 8 unknown coefficients in this transformation can be solved using the for vertices of the polygon such that in matrix form
Equation 3

This resulting transfer function is valid for all points with in the polygon as long as it is not to large.

The ideal grid required in this method can easily be generated using the least distorted area in the distorted image. The dimensions of the least distorted "box" can be used to construct the ideal grid. We would then just need to determine the transfer function for each pair of distorted and undistorted "boxes." Using these transfer function we can now solve equation 2 to determine the distorted coordinates of each point in the ideal image. That is we can now determine the graylevel values for each ideal undistorted image coordinate by copying the graylevel value of its corresponding distorted coordinate. This is the second step of our correction process.

However, most of the time our calculated distorted coordinates are not integers. For such cases we need to interpolate the graylevel value for our ideal undistorted image. Three commonly used interpolation techniques are the nearest neighbor, bilinear interpolation, and cubic convolution. In this activity we choose to implement bilinear interpolation which has a much better quality than nearest neighbor and is much faster compared to cubic convolution.
Equation 4
Equation 5

Bilinear interpolation works as in equation 4. That is, the greylevel v is assigned to the coordinate (xhat,yhat). so by solving equation 4 we can obtain the gray values even for non-integer coordinates. The unknown coefficients of equation 4 can likewise be determined similar to equation 3 but know we use the four nearest pixels around (xhat,yhat) (figure 3, equation 5).
Figure 3. Visualization of Bilinear Interpolation

In this activity I used an image with barrel distortion downloaded from the internet. Figure 4 shows the original image and the ideal grid I generated using the least distorted area in the image. After implementing the method we have discussed I was able to remove the obvious barrel distortion of the image.
Figure 4. (left) Original distorted image with indication of corrected area (red box) and area of least distortion (yellow box). (center) Ideal grid generated from area of least distortion. (right and bottom) Resulting corrected image.

The result presented in figure 4 shows that our method is very effective in removing barrel distortion. It is clearly seen that the previously curved lines are now vertically and horizontally straight. The bricks that previously had different sizes are now more uniform. The only inaccuracy we can see is that some of the bricks are slightly tilted. It is hard to determine whether they should be tilted or not but I believe it is safe to assume that most of them are squarely laid-out. Still, even with this slight error, we see very promising and convincing results.

Figure 5. Corrected image with color. The red circles identify areas with erroneous color.

Figure 5 shows a colored version of our result. This was generated by implementing the correction process for the 3 color channels and combining them into one image. This colored result shows one more error. We clearly see that at some points have colors that are obviously not accurate. This is because at these points one or two of the three color components are not properly represented. Using the same reference points in all the color channels may result in some points having the wrong color component values. In other words although the gray scale result looks almost perfect it cannot be directly implemented to a colored image and expect the same level of accuracy.

I thank Ate Cherry for helping me understand the correction procedure. I give my self a grade of 10!!

Image source:
http://www.nicovandijk.net/lenses.htm

Main Reference:
A13 – Correcting Geometric Distortions by Maricor Soriano, AP186 2009

No comments:

Post a Comment