Monday, August 18, 2008
Activity 12: Correcting Geometric Distortions
Continuing our grand pursuit of using image processing techniques to solve real-life problems, we move to removing geometric distortions from images. Geometric distortions occur because low-end cameras exist! (Hahaha! To make the life of a physicist easier, then buy high-end cameras! Kidding!) There are two kinds of distortions that may occur: a pin-cushion distortion and a barrel distortion. These distortions are better shown than meticulously explained:



In the problem we will particularly solve, we are given an image of a Capiz window with an obvious barrel distortion:



We "selectively select" the part where the distortion is most evident: The Capiz tiles.



Then, from the image, we "envision" an "ideal" image by locating the most "undistorted" Capiz tile, obtaining its area, and assuming every tile is exactly the same. In my case I chose the tile in the 7th row, 5th column. The resulting "ideal" image is shown below:



Thinking of both images (the distorted original and the ideal) as matrices that has a correlation with one another we can easily find the "transformation matrix" that links the two together (since they are obviously NOT the same! Hahaha!). Let's say the "end points" of the first Capiz tile correspond to four (x,y) pixel values, due to its distortion, these values do not correspond to the (x,y) values of the ideal image! So we equate one another to the proper matrix forms in order to get the "transformation matrix" which we would then apply to correct the distorted image! Gets? To further elaborate, I'm posting essential parts of Dr. Soriano's lecture:



This was the code I used to implement the process:

chdir('G:\poy\poy backup\physics\186\paper 12');
im=imread('realdistorted.jpg');
im=im2gray(im);
M=[];
//I chose a wide area polygon than a relationship of just one square
xi=[13; 87; 87; 16];
yi=[15; 15; 180; 181];
T=[13 14 13*14 1; 86 14 86*14 1; 86 177 86*177 1; 13 177 13*177 1];
C1=inv(T)*xi;
C2=inv(T)*yi;
for i=1:x
for j=1:y
x_im=C1(1)*i+C1(2)*j+C1(3)*i*j+C1(4);
y_im=C2(1)*i+C2(2)*j+C2(3)*i*j+C2(4);
if x_im>=x
x_im=x;
end
if y_im>=y
y_im=y;
end
M(i, j)=im(round(x_im), round(y_im));
end
end
scf(2);
imshow(M, []);

The result I obtained is best observed as a GIF file, notice the difference in the lines, they're straighter!!!:



Acknowledgments

This activity is HARD... no, LOOOOOONG!!! HAHAHA!!! But I did it! And I can confidently say that I am "semi-independent" in performing this activity but I really have to thank Jeric for giving me a head start in making a right code. I give myself 10/10 neutrinos!

posted by poy @ 10:50 PM  
0 Comments:
Post a Comment
<< Home
 
 
About Me

Name: poy
Home: Quezon City, NCR, Philippines
About Me:
See my complete profile
Previous Post
Archives
Template by
Blogger templates