Activity 12: Correcting Geometric Distortions (partial)

July 31, 2008 at 5:52 pm (Uncategorized)

*note. i still have to implement grayscale interpolation. as of the moment, i only did the pixel coordinate correction.

We can imagine our image as if it was warped through some linear transformation.

To better visualize the problem, we assume that we have a straight grid as pictured in the right side of the above image. However, since the camera has inherent geometrical aberrations, the picture we image would be warped and transformation is given as

where x’ and y’ are the coordinates of the pixels x,y (orig image) in the distorted image. Further, we assume that the transformation is is that of a bilinear function as shown below.

Thus, we have the transformation function as

The values of c are determined from the four vertices of corresponding polygon in the distorted image and ideal image. In this activity, I highlighted my region of interest and measured the actual and ideal pixel location of the region of interest. The green-highlighted section is the ideal locations of the grids.

However, the values of  and are valid in the included polygon.

My code below was executed from this set of instructions (from Dr Soriano’s lecture).

1. Obtain image.

2. From the most undistorted portion of the image, e.g. at the optical axis of the camera, count the number of pixels down and across one box.

3. Generate the ideal grid vertex points (just the coordinates).

4. For each rectangle compute c1 to c8 using pairs of equations (x’s,y’s) from the four corner points.

In compact matrix form, we have and . We can solve for the c’s using

and .

5. Per pixel in the ideal rectangle, determine the location of that point in the distorted image using

6. If the computed distorted location is integer-valued, copy the grayscale value from the distorted image onto the blank pixel. If the location is not integer-valued, compute the interpolated grayscale value using:

im=imread(‘image.jpg’);
im=im2gray(im);
[x,y]=size(im);
ideal=zeros(x,y);
for i=1 : 10 : x
ideal(i, :)=ones(y);
end

for j=1:8:y
ideal(:, j)=ones(x);
end
scf(1);
imshow(ideal, []);
blank=[];
xi=[31; 183; 183; 31];
yi=[48; 50; 97; 95];
T=[31 48 31*48 1; 245 48 245*48 1; 245 95 145*95 1; 31 95 31*95 1];
c14=inv(T)*xi;
c56=inv(T)*yi;
for i=1 : x
for j=1:y
x_im=c14(1)*i+c14(2)*j+c14(3)*i*j+c14(4);
y_im=c56(1)*i+c56(2)*j+c56(3)*i*j+c56(4);
if x_im>=x
x_im=x;
end
if y_im>=y
y_im=y;
end
blank(i, j)=im(round(x_im), round(y_im));
end
end
scf(2);
imshow(blank, []);
//for j=1:10:y
// ideal(:, y)=ones(x);
//end

Leave a comment