Thursday, September 17, 2009

A16 Neural Networks

We are done with pattern recognition and classification by (1) mean distance method and (2) probabilistic classification by LDA. Let us now try another classification technique by way of (3) probabilistic neural networks. A neural network is a mathematical model of how neurons in the brain work. Among the many function and varied capabilities of the brain is classification.

Just like the brain, neural network can perform tasks based on experience. It can carry out mapping or classification only after learning the patterns of the classification scheme, something which can be taught by giving examples or training the program. Each example serves to improve the neural network program’s recognition processing.

The architecture of this neural network is illustrated as:

Input layer- is where the features of the set are fed. This first layer computes distances from the input vector to the training input vectors and produces a vector whose elements indicate how close this input is to a training input.


Hidden layer- acts contributions from the input layer by computing the summed probabilities for each class of inputs and passes the results to the output layer.


Output layer-outputs which class these set of feature vectors pertain/ belong to.

In Scilab, we use ANN or Artificial Neural Network to do the classification of the set of features extracted in activity 14. The program used was adapted from Cole’ Blog.



In Activity 14, the samples consisted of 2 class of chips, the Cheese- it labeled as (0) and Pillows as (1). Each class has 12 samples and each sample is described by 4 features namely: hor*ver or area 1, area 2(#pixels), perimeter, and the ratio of area2/perimeter.


Procedure:

1.Specify the no. of neurons in (4)input layer,(4) hidden layer and (1)output layer.


The ANN architecture

N = [4,4,1];

There are 4 features (normalized) extracted from each sample:
These features were specified as x:

x=read('data6train.txt',-1,4);


2. Training

Used 12 objects, 6 from each class in training process as the example classification

t=[0 0 0 0 0 0 1 1 1 1 1 1];


3. Learning

The learning rate and threshold are specified by:

lp = [0.1,0];

Here 0.1 and 0 is the threshold for the error tolerated by the network:

Training cycles or iterations:

T = 1000;


4. Run the classification using ann_FF_Std_online and ann_FF_run(x,N,W);


W = ann_FF_Std_online(x,t,N,W,lp,T);

c=ann_FF_run(x,N,W);

c=c'



5. Results and Discussion

The expected output values were supposed to be in 0’s and 1’s. However the actual results as seen in column 1 Table1 were in decimal. Still, values for each sample were very close to 0 and 1’s and from here we can say that the program has learned the proper grouping of each sample.

Next, I tested whether the program is now ready for the real classification.


This test worked well and the results show that the program worked with 100% correct classification.
Then to see whether or not the program is dependent on the arrangement of the samples, I shuffled the arrangement of the test samples.

Again the test worked well and the samples were classified correctly and showed that this time the program can work smoothly as it can adapt to the arrangement of the inputs.
Then I tested the effects of varying the parameter T which is the no. of cycles or iterations.

As expected lowering the T value reduced the accuracy of the classification while increasing it improves the accuracy, although doing that took a rather a longer runtime. Still the classifications for both cases were all correct.


Afterwards I shuffled the 24 samples to test whether this program can still sort them into their respected classes. Then I just rearranged the output in order.


These tests proved that the program has learned the classification pattern and is 100% accurate.

SOURCE: A16 Neural Networks Manual and Cole' Blog

ASSESSMENT: 10/10 because I was able to use NN in Scilab and make it classify my samples into their respective classes correctly.

Wednesday, September 16, 2009

A17 Photometric Stereo

Fig1. Images I1,I2,I3 and I4


Based on the manual for this activity , from the point sources locations (1) and intensities obtained from the 4 images of the object we are able to compute for g via equation (2). Next we determine the normal vector(3), and then compute component surface normals(nx,ny,nz) from each row.

And relate these surface normals to the partial derivatives of f (4) and compute the elevation z=f(u,v) by taking the integral of in (5) via cumsum of (4) over x and y. This can be easily plotted in 3d using mesh.

Fig 2. 3D plot of the object shape using mesh


SOURCE: A17 Photometric Stereo Manual


ASSESSMENT: 10 because I was able to reconstruct the surface using the directions in the manual :) and I was able to use mesh :)

Wednesday, September 2, 2009

A15 Probabilistic Classification

Linear discriminant analysis (LDA) is one of the techniques used pattern recognition to classify two or more classes of objects and in this case the separation of the 2 kinds of chips using the 4 features aextracte from previous activities.

The classification works by taking the combinations of features based on differences. Say the objects’ features are linearly separable, we can use linear discriminant model (LDA) formula given as:


SOURCE: http://people.revoledu.com/kardi/tutorial/LDA/LDA.html#LDA

This is a summary of the data used in activity 14:

Table 1.
Procedure:
1. LDA
After processing the data in Table 1 as input x in the implemented LDA formula in Scilab, each sample was easily classified as either belonging in class 1 or 2 depending on its value f.
2. Determine if f1>f2:
By comparison, a large value of f1 would mean that this object belonged to class 1 and and class 2 if f1 is small.
The LDA worked successfully in assigning the 24 samples to its respective class.

ASSESSMENT: 10/10 because I successfully implemented LDA in scilab and used EXCEL to summarize the data into tables :)

Wednesday, August 26, 2009

A14 Pattern Recognition

PROCEDURE:
1. Trials
Pattern recognition by way of shape classification was implemented in this activity where I took an image full of various shapes(Fig.1a),convert it to black and white after thresholding, and took the edges of each shape, then labeled each shape and computed its perimeter by bwlabel and tabul.

a.original imageb. bw of the original im


c. thind. skeleton

Figure1.

Figure 2. Took the edge this time
Figure 3. Barplot of each shape tagged from 1-30 and its corresponding perimeter.

From Figure 3, the tally of the shapes are :DEW: 8,HEART: 5, petal :6, circle :10, leaf:1 and these results agree with the number of occurrence of those patterns in Figure 1,2. :)


2. Minimum Distance Classification
Applying this,we captured an image of 2 kinds(2 class) of chips and extracted the best features of the objects. After obtaining these features I separated them in half as training feature and test features.For each class, I computed mean feature vector mj and which I then used to classify the remaining test features. The one with the minimum distance was used determining which class an object belonged to. Afterward, the percent error of the classifier was then computed.

The original image (Fig4)has these vertical that I cannot remove using fft so I just used Gimp to remove it.Then I converted the image to grayscale then to bw after thresholding. I used dilation and erosion to finally clean the image. Here they are(Fig5).
I then extracted the following features:

1. AREA1 from the vertical and horizontal length of each chip,

hor=[];ver=[];this=1;

for i=2:n

[x,y]=find(L==i); hor(this)=max(y)-min(y); ver(this)=max(x)-min(x);

area1=ver.*hor; this=this+1;

end

area1



2. AREA from the length of the bwlabel(L,n) then the are itself by area=tabul(L,"i")


3. the perimeter using edge of the bwlabel(L,n) then the are itself by perimeter=tabul(L,"i")


4. ratio of area /perimeter by (area./perimeter)


5. rgb component of each chip by

r=im1(:,:,1);g=im1(:,:,2);b=im1(:,:,3);red=[];blue=[];green=[];

this=1;for i=1:n

[x,y]=find(L==i);

//at that chip lang

red(this)=mean(r(x));

green(this)=mean(g(x));

blue(this)=mean(b(x));

this=this+1;

end

//lhat ng chip

red

green

blue


After obtaining these features I separated them in half as training feature and test features.For each class, I computed mean feature vector mj and which I then used to classify the remaining test features. The one with the minimum distance was used determinining which class an object belonged to. Afterwards, the percent error of the classifier was then computed.


Fig 4 Image of the chips :), cheeseit and pillows

Fig 5 After removing the lines, graycaling, converting to bw, dilation and erosion .
From here got the area from the vertical*horizontal line running across each chip and area from the sum(pixels)

Fig 6 Got the perimeter from the edges.
Table1: Summary of the extracted features.

Table 2. Summary of the data after Minimum Distance Classification. In the classification I just used area1, area,perimeter, and area/perimeter in the classification(para madali).

SOURCE: A14 Pattern Recognition Manual

ASSESSMENT: 10/10 because I implemented my idea of using of using only bwlabel and tabul in getting the features from areas to RGB of each sample.I was also able to apply other techniques from the previous activity. Then the classifier was 100% error free in classifying the two chips. (yes:)

Wednesday, August 19, 2009

A13 – Correcting Geometric Distortions

Two forms of distortion commonly encountered in image processing :

1.Barrel effect

This effect gives the image an inflated or blown up appearance .


2. Pincushion Effect

This effect gives the opposite of barrel distortion wherein the image suffers from deflated appearance.



PROCEDURE:
To correct for distortion we need to capture a reference image with a regularly occuring pattern so that we can visualize the distortion across the image frame.


The correction will be done on two image properties:
1. pixel coordinates and
2. graylevel values

1. From the most undistorted part of the image the ideal grid vertex points were located and the reference image for the corrected constructed.
2.For each rectangle compute c1 to c8 using pairs of equations (x's,y's) from
the four corner points. Per pixel in the ideal rectangle, the location of that point in the
distorted image was determined. If the computed distorted location is integer-valued, the grayscale value from the distorted image onto the blank pixel was used. If the location was not integer-valued, the interpolated grayscale value was computed instead using the equations in the manula provided in the source.

SOURCE: A13 Correcting Geometric Distortions Manual

Figure 1 . Distorted image



Figure 2. Reference image for the distorted image in figure1. pixel distances from a square in fig1.


Since it was really difficult to correct the distortion in Figure 1 at once, I just tried to correct the distortion in 1/2 the image.
So far


Figure 3. a. Half portion of image 1, (b) Corrected image distortion using linear approximation and (c) using bilinear interpolation. The crooked lines in b and c are partly due to the error in the location of the corner points in locate(and the sobrang grabeng distortion).
The quality of the corrected image using linear approximation was not as good as that of the bilinear interpolation since the image for the linear approximation using only the nearest neighbors resulted to more jagged corners for each square in the grid.


ASSESSMENT: 9/10, because I didn't get the complete distortion correction of the image though I was able to implement the distortion correction in Scilab. The main problem and the hardest part was the location of the distorted points xi and yi. Eventhough I used locate I still couldn't get the exact endpoint for each square. I should have limited myself in either barrel or pincushion distortion. :)

GRATITUDE:I would like to thank Mandee and Alva for teaching me how to do this activity :)

Thursday, August 6, 2009

A10 Preprocessing Text

Int this activity we tried to extract handwritten text from an imaged document with lines. This is often used in in handwriting recognition where individual examples of letters must be extracted.










Fig. 5. Used the enhanced image in Figure 4. So, from the left the image, its shifted Fourier tranform, its mask to remove the horizontal lines and the final image with only the text and the horizontal lines gone.


Figure 6. The histogram of the masked or cleaned image with handwriting. After thresholding , it was converted to a binary image to extract the text, but the text is still dirty.

In Figure 5 the desired text is already achieved and the image cleaned , but trying to extract the text requires more cleaning. But I think results inFigure 5 is already ok. I am still working on the threshoding and cleaning Figure 5 image... to get better results than what is shown in Figure 6.

Wednesday, August 5, 2009

A11 Color Image Processing

Following the set procedure:
1.We take the picture of colorful objects and an ensemble of objects with different shades , in this case shades in green from leaves.
2. Under a fixed light source (sunlight, sunny) we took the their picture under proper and incorrect white balancing through the Auto, Cloudy, Daylight , Fluorescent and Incandescent settings.
3. We proscessed these images through the white and gray world algorithm.
4. For the WWA we took the the RGB values of pixels belonging to the white object of objects. Let these be Rw, Gw, Bw and implement the White Patch algorithm by dividing all the pixels in the red layer of the image by Rw, the green layer by Gw and the blue layer by Bw. After making sure that no pixel exceed 1.0, the resulting image is shown in the second column in Figure 1.
5. For the GWA we took the average red, green and bluevalue of the captured image and used them as the balancing constants and the resulting image is shown in the third column.

Figure 1.

6. Afterwards we did the same procedure for the ensemble of green leaves and put them agains a white background. And did both for the proper and improper white balancing for the outdoor illumination where AUTO nad DAYLIGHT provide the proper white balancing while CLOUDY, FLURESCENT and INCANDESCENT are the improper.


Haha I couldn't make the imwrite fcn work in this activity so I just resorted to PrtSc and the images are saturated since imshow has limited resolution and still saturated after multiplying the imshow by 0.5.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++