Tuesday, July 29, 2008

..on camera calibration

A simple image is not an exact projection of the actual object. Some informations are lost. The task is to recover these lost details. And one of the important step is camera calibration. The goal is to know the transformation from the 3D world coordinates to the 2D image coordinates.
















Below is an image of a 3D calibration checkboard. We designated an origin and using a right-hand coordinate system, we chose 25 square corners and measured their coordinates (Yi, Zi) with respect to the origin. We also determined their real world coordinates (Xo, Yo, Zo).




















We now proceed with determining the transformation matrix a. The equation is given by














Finally, we solve for a using




To check for the accuracy, we randomly chose 4 points on the checkboard and using their real world coordinates, we calculated for their image coordinates. We measured the deviation from the theoretical value using the eucleadian distance. The results are: 1.12, 1.31, 1.44, and 0.98. These values shows that the calculated coordinates are less than 2 pixels away from the actual location. the accuracy is amazing.

I was able to finish the activity with high accuracy. I want to give myself a 10.








Tuesday, July 22, 2008

..on preprocessing handwritten text

Below is a digitalized image of a document. Our goal is to extract the handwritten text and to remove the horizontal lines.












We remove the vertical lines using the same technique used on the previous activity(lunar image). The Fourier Transform of the image is shown below. To get rid of the horizontal lines, we have to block the frequencies corresponding to it. Thus, we introduced the filter below.
























The resulting image is free of the horizontal lines. We then binarized this image and enhanced it using morphological operations.












Below is the final image. Though we are successful in getting rid of the horizontal lines and the extraction of the handwritten text, the quality is not enhanced. The letter count is 106 which is obviously higher than the actual number of letters in the text.












I was able to finish the activity. Though the lines were successfully removed, the extracted text is not well enhanced. I hope a 9 would be reasonable.

Thursday, July 17, 2008

..on binary operations

Below is an image of scattered punched paper. Our goal is approximate the size (pixel count) of a single punched paper.




















Since the image is relatively large, we cut it down into twelve 256X256 subimages. We then convert them into binary images. Below are examples of the binary images.

























These images are not ideal. We enhanced them further by applying opening and closing morphology operator. These clean the image of isolated pixel and small holes. Below are the results of the enhancement.

























We now measure the pixel count for each blob. Since the enhancement was not able to perfectly separate individual punched paper, there are big blobs on the image. We need to filter out this outliers. We do this by getting the histogram of the pixel count.


















For this particular plot, we consider only those values between 300-600 since it is in this range that we have an approximate Gaussian distribution. Finally, we take the mean of the pixel count within this range. Our result is 428.89 with a standard deviation of 71.53. To check, we processed images of individual punched paper and measured the pixel count. The average value is 456.1 with a standard deviation of 70.69. This is a 6% error.

Below is the Scilab code. I was able to implement the program such that it automatically outputs the mean pixel count and standard deviation for all images.

numt=[];
v=0;
for j=1:1:12
//upload image
dir('E:\acads\1st sem 08-09\186\activity9');
str=strcat(['C2_',string(j),'.jpg']);
image1=imread(str);

//convert to gray scale
image1=im2gray(image1);

//convert to binary
image1=im2bw(image1,229/255);
//f1=scf(1);imshow(image1);

//make structuring element
sq=ones(2,2);
se=mkfftfilter(sq,'binary',1);

//opening
C1=erode(image1,se,[1,1]);
//f2=scf(2);imshow(C1);
C2=dilate(C1,se,[1,1]);
//f3=scf(3);imshow(C2);

//closing
C3=dilate(C2,se,[1,1]);
//f4=scf(4);imshow(C3);
C4=erode(C3,se,[1,1]);
//f4=scf(2);imshow(C4);


//labeling
[mat,n]=bwlabel(C4);

//counting pixel size
val=[];
num=[];
counter=1;
for i=1:1:n
[x,y]=find(mat==i);
val(counter)=i;
num(counter)=length(x);
counter=counter+1;
end

for i=1:1:n
//mm=v+i
numt(v+i)=num(i);
end
v=v+n;

end

//histplot([10:30:800],numt);

//neglect outlier
numf=[];
c=1;
for i=1:1:length(numt)
if numt(i)>=300 & numt(i)<=600
numf(c)=numt(i);
c=c+1;
end
end

mean(numf)
stdev(numf)

I was able complete the activity. I was also able to implement the program automatically. I think I would give myself a 10 plus the bonus (5), thus a 15.=)

Tuesday, July 15, 2008

..on morphological operations

Below are the results when different shapes are subjected to dilation and erosion using different structuring element (SE). Dilation results to an increased size of the original image while erosion reduces the size. The resulting shape is affected by the SE. The 1st column image are the original shapes, 2nd column are the results of dilation, and the third column are the results of erosion.

1. SE: 4x4 ones























































2. SE: 2x4 ones


























































3. SE: 4x2 ones





















































4. SE: cross 5 pixel long 1 pixel thick





















































The results are consistent with the predicted sketches. As expected, the dilated image is bigger than the original while the eroded is smaller. The resulting image is affected by the SE used.

I was able to finish the activity and my results are consistent. I want to give myself a 10.

Wednesday, July 9, 2008

..on enhancement on the frequency domain

Below are 2D sinusoidal patterns in increasing frequency (f=1,f=4,f=16).

Patterns





f=1










f=4











f=16






Taking the fourier transform (FT) of these patterns, we would notice that as the frequency increases, the separation between the two peaks increases. The two symmetric peaks represent the frequency of the pattern. As the frequency increases, the peaks deviates further from the center.

Fourier Transform of the Patterns





f=1










f=4











f=16






We now consider rotated patterns. These patterns were generated by:
z = sin(2*pi*f*(Y*sin(theta) + X*cos(theta))) where theta=30. The frequencies are f=4 and f=16.

Rotated Patterns





f=4










f=16






The resulting FT are also rotated. The rotation of the pattern results to the rotation of their FT's.

Fourier Transform of the Rotated Patterns






f=4










f=16






We now consider a combination of sinusoidal patterns on both X and Y axis, as well as rotated patterns.

Combined Patterns




fx=4
fy=4









fx=4
fy=16










f=8
theta=30






The resulting FT created multiple peaks. For fx=fy=4, the peaks are symmetric and are equidistant. When the frequency along one direction is increase, the peaks are stretch further along that direction. Again, we observe that the rotation of the pattern resulted to the rotation of the FT.

Fourier Transform of the Combined Patterns





fx=4
fy=4









fx=4
fy=16









f=8
theta=30






Fingerprint: Ridge Enhancement

Below is an image of a fingerprint in grayscale.












We take the FT of the image and filter out other frequencies to enhanced the ridges.












Lunar Landing Scanned Pictures: Line Removal

We also apply the same technique on the image below.















grayscale










Filter











Resulting Image





The lines are minimized.

I was able to complete the activity but the resulting images are not perfectly enhanced. I don't think I deserve a 10 on this. I hope a 9 would be justifiable.

Acknowledgment to Ed for the scanned fingerprint.