Thursday, August 7, 2008

Activity 12: Correcting Geometric Distortions

For this activity, we were asked to correct geometric aberrations such as distortion in images as the one shown below.



To start, we were given the distorted image above to work on. The coordinate of the ideal straight image is (x, y), whereas the distorted image has (x',y'). A pixel location was mapped to by some transformation function given by the expression:



A rectangle was created from the most undistorted portion of the image, in this case, at the optical axis of the camera. Here, the number of pixels down and across one box was determined. The four vertices of the corresponding rectangle in both the ideal and the distorted images give the values for the eight unknowns (c1 to c8) in the equations, which are only valid within the polygon. Each vertex also has its corresponding and coordinates.

To compute for the coefficients, the following equations were used:


The location of that point in the distorted image is given by:



If the computed distorted location is integer-valued, the grayscale value is computed from the distorted image onto the blank pixel. Otherwise, the interpolated grayscale value can be computed using the following equation:



The resulting image is therefore:



The code used is:

chdir('G:\186\activity12');
image = imread('image.jpg');
image = im2gray(image);
[x,y] = size(image);
ideal = zeros(x,y);

for i = 1:10:x
ideal(i,:) = ones(y);
//imshow(image)
end
for j=1:8:y
ideal(:, j) = ones(x);
end

xi=[99; 183; 183; 99];
yi=[49; 50; 97; 95];
transpose=[99 48 99*48 1; 245 48 245*48 1; 245 95 245*95 1; 99 95 99*95 1];
c14 = inv(transpose)*xi;
c56 = inv(transpose)*yi;

for i = 1:x
for j = 1:y
imagex = c14(1)*i + c14(2)*j + c14(3)*i*j + c14(4);
imagey = c56(1)*i + c56(2)*j + c56(3)*i*j + c56(4);
if imagex >= x
imagex = x;
end
if imagey >= y
imagey = y;
end
newim(i,j) = image(round(imagex),round(imagey));
end
end
//imshow(newim);

Rating – 9 bec. although the distortion was fixed, the image does not look that good.
Acknowledgement – Jeric for helping me with the code.

No comments: