In imaging, light rays from a point on an object is captured by camera lenses, refracted and focused onto the recording plane of the camera, whether on a film or a CCD. However, due to the shape of the lenses, light rays from a single object point does not focus on a single point on the recording plane. This is due to the fact that light rays refracting at the edge of spherical lenses (marginal rays) behave differently than those close to the center or the optic axis of the lens (paraxial rays). For the same reason, parts of the object directly 'passing' through the edge of the lenses upon imaging would result to some geometric distortions. The two most common are the pincushion and barrel distortion, which produce images shaped like a pincushion and a barrel, respectively.
In metrology, it is critical to obtain highly accurate data from images. In this regard, distortions are undesirable, causing errors in the measurements. In this activity, a method for correcting geometric distortions is presented.
The main idea behind the reconstruction is to image a regularly occurring pattern, such as a grid or a checkerboard. From the imaged pattern, coordinates upon distortion for each point on the ideal pattern are known and can provide the necessary information for obtaining the distorting function (see image below).
Ideal grid (right) and distorted grid (left) with
corresponding vertex points specified by the arrow
(image taken from [1]).
Other points on the ideal image can then be mapped on the distorted image using the same transformation as the vertices. Using the four vertices of a square in the pattern, a relation can be obtained regarding the transformation in the coordinates of the distorted grid:
The same transformation relation can be used for the points inside the square. To obtain this relation, matrix operations are used to calculate for the coefficients, C:
These coefficients is used to calculate for all the points inside the square:
Grayscale or RGB values of the ideal image can then be obtained from the corresponding values on the distorted image upon knowing points of the distorted image corresponding to the ideal image. Since images are indexed in pixel coordinates, only integer values are accessed for the distorted image. Different algorithms can be used to determine the grayscale or RGB value for cases when non-integer valued coordinates on the distorted image is calculated. One is the nearest neighbor algorithm, which basically takes the value of the distorted image at the nearest integer coordinate of the calculated distorted coordinates. Another algorithm, bilinear interpolation, interpolates the value using the four nearest neighbor pixels of the calculated distorted coordinates. Using the equation:
the grayscale or RGB value v(x,y) is obtained following similar matrix operations for obtaining the distorted coordinates. The four nearest neighbor pixel values are used in the same way as the four vertices of the square, for calculating the coefficients a, b, c, and d. The pixel value for distorted coordinate is then obtained and set as value on the ideal image to complete the reconstruction.
The method described above can also be used to correct other types of distortion since the distorted image is mapped to an ideal grid with a specific transformation. This transformation can be of different type to correct for different distortions.
Two trials were made for correcting of the image below. For analysis, reconstruction using vertices of the squares of the grid overlaying the image (Trial 1) was compared one using vertices of the square composed of the four basic squares in the image (Trial 2).The method described above can also be used to correct other types of distortion since the distorted image is mapped to an ideal grid with a specific transformation. This transformation can be of different type to correct for different distortions.
(original image taken from http://www.karbosguide.com/books/photobook/chapter34.htm)
Coordinates of the vertices were obtained using locate() in Scilab. Then the ideal grid was constructed by selecting the coordinates of the square with (approximately) no distortions, and building up all the other squares in the ideal image. The undistorted square used for Trial 2 is the square composed of the four central squares in the image specified by the four red dots. For Trial 1, only the upper left square in the four central squares was used.
Using the vertices of the squares in the distorted and ideal grid, the coefficients were obtained to determine distorted coordinates for all the points inside the square. Nearest neighbor and bilinear interpolation algorithms were then applied to obtain the RGB values of the ideal image. The results of the reconstructions are shown below (the whole image was not reconstructed).
***Click on the image below for a larger image
Trial 1
Using the vertices of the squares in the distorted and ideal grid, the coefficients were obtained to determine distorted coordinates for all the points inside the square. Nearest neighbor and bilinear interpolation algorithms were then applied to obtain the RGB values of the ideal image. The results of the reconstructions are shown below (the whole image was not reconstructed).
***Click on the image below for a larger image
Trial 1
Nearest-neighbor and Bilinear interpolation
Trial 2As demonstrated in the results, the bilinear interpolation algorithm provides a better reconstruction compared to the nearest-neighbor for both trials. The bilinear interpolation gives a more accurate RGB value. This is better shown in the lines of the grid. The nearest-neighbor algorithm has lines that are more jagged.
In comparing the two trials, it seems logical that using the small squares should result to a better reconstruction. Zooming in on one part of the image, this is shown more evidently (shown below, for the bilinear interpolation images). The reconstruction for Trial 1 is much smoother compared to Trial 2, which contains more artifacts. The reason for this is because the small squares would provide a more specific set of coefficients for calculation of distorted grid coordinates in an area. However, as noticed in the images above, the reconstructions for Trial 1 are actually rectangular, while for Trial 2, the images are square. The obtained undistorted central square for Trial 1 is not a square, not like the square obtained for Trial 2. As noticed, the square used in Trial 1 is not directly at the center, while for Trial 2, it is exactly at the center. The approximation that the square chosen is undistorted may not be valid for Trial 1. For Trial 2, since the square is directly at the center, there would be no offset on whether the square is perfectly undistorted.
In this activity, I would like to give myself a grade of 10 for producing a very good correction of an image with relatively large distortion. Moreover, I also examined the use of smaller squares compared to larger squares in the reconstruction (Trial 1 and 2).
I would like to thanks Ms. Winsome Chloe Rara and Mr. Mark Jayson Villangca for their help in doing this activity. I also acknowledge Dr. Maricor Soriano for her discussions regarding this activity.
In comparing the two trials, it seems logical that using the small squares should result to a better reconstruction. Zooming in on one part of the image, this is shown more evidently (shown below, for the bilinear interpolation images). The reconstruction for Trial 1 is much smoother compared to Trial 2, which contains more artifacts. The reason for this is because the small squares would provide a more specific set of coefficients for calculation of distorted grid coordinates in an area. However, as noticed in the images above, the reconstructions for Trial 1 are actually rectangular, while for Trial 2, the images are square. The obtained undistorted central square for Trial 1 is not a square, not like the square obtained for Trial 2. As noticed, the square used in Trial 1 is not directly at the center, while for Trial 2, it is exactly at the center. The approximation that the square chosen is undistorted may not be valid for Trial 1. For Trial 2, since the square is directly at the center, there would be no offset on whether the square is perfectly undistorted.
Trial
1 2
In this activity, I would like to give myself a grade of 10 for producing a very good correction of an image with relatively large distortion. Moreover, I also examined the use of smaller squares compared to larger squares in the reconstruction (Trial 1 and 2).
I would like to thanks Ms. Winsome Chloe Rara and Mr. Mark Jayson Villangca for their help in doing this activity. I also acknowledge Dr. Maricor Soriano for her discussions regarding this activity.
Reference
[1] M. Soriano, Applied Physics 186 Activity 13 Correcting Geometric Distortions Manual, 2009.
[1] M. Soriano, Applied Physics 186 Activity 13 Correcting Geometric Distortions Manual, 2009.
No comments:
Post a Comment