Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowtham1729 committed Oct 25, 2019
0 parents commit e48fe69
Show file tree
Hide file tree
Showing 180 changed files with 874 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# FACE RECOGNITION USING EIGEN FACES
This is a Face Recognition algorithm designed to detect faces in real time. This approach is fast enough to implement it on real time. This approach is based on the paper [Face recognition using eigenfaces by Matthew A. Turk and Alex P. Pentland](https://ieeexplore.ieee.org/document/139758)

[The YaleFaces Dataset](https://vismod.media.mit.edu/vismod/classes/mas622-00/datasets/) is used for training and testing the algorithm.

## Development
This paper is implemented in python3.

Python packages used for the implementation are:
1. numpy
2. matplotlib
3. sklearn

To install these packages run the following code
```pip install -r requirements.txt```

All the Ipython notebooks are self explanatory
59 changes: 59 additions & 0 deletions REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Face Recognition
Inorder to detect the faces from the given image, we first need get the feature vectors for each image. Although we have the image itself as two dimensional vector, we need something which is simple and in a much lower dimension to compare them easily.

So, we will find the eigen values and eigen vectors of the matrix containing all the images. These eigen vectors are called as Eigen Faces. Each of them represent a feature of an image. Unlike what we think these are not intutive features like face shape, nose structure, color, eyes etc., They are rather counter intutive. We will consider top eigen faces (principal components) and use them for predicting our new image. This complete mathematical dsription is given in the paper mentioned above.

## Implementation

Every Two dimensional Image can be represented as 3 dimensional matrix with the three channels being Red, Blue and Green. We need to convert this 3d matrix into a 2d matrix by converting the image to grayscale. Grayscale can be roughly considered as an average of these three channels. Although, in order to convert it into a better looking grayscale image we need to take ```gray_scale = ((0.3 * R) + (0.59 * G) + (0.11 * B))```

Once we get a grayscale image(2d matrix). In order to represent all the images in the form of a single matrix. We will flatten them and then combine them into a single matrix.

Gray Scale Image in the Dataset,
![Some Image](images/img1.png)

Before we actually flatten and combine them, we need to take the average of all the images and subtract the original image from the average image.

Average Image look like this,

![Average Image](images/avg.png)

After Subtracting the average from the original image it look like this.

![minus Image](images/minus.png)

Now, Find the Covariance Matrix of this matrix containing all the images using the below formula.

![Covariance Matrix](images/covariance.png)

**Note**: If we try to find the eigen values of the matrix using the above we will find it very difficult considering our computational resources. Hence, we will find the eigen values and vectors(vi) for Transpose(A)*A
And then we can get eigen vectors of the required matrix using the below formula.

![Eigen Values](images/eigen.png)

The obtained eigenfaces look like this,

![Average Image](images/ef.png)

Once we obtain the eigen faces take top eigenfaces and get the weights of each image in dataset using the below formula.
![Average Image](images/weights.png)

Once we obtain all the images we just need to return the class of the image nearest to the test image. We can use any distance metric like euclidean distance.

## Results

For the reults, the dataset is divided into 70% as training data and 30% as test data. We have 15 different images with 11 images each with slightly varying facial expressions and lighting conditions.

- Test Accuracy - 100%
- F1 Score -
- Confusion matrix,

![Confusion Matrix](images/cm.png)

Correctly Classified Test Images,

![correct Matrix](images/correct.png.png)

Misclassified Test Images

![wrong Matrix](images/wrong.png)
795 changes: 795 additions & 0 deletions Recognizer.ipynb

Large diffs are not rendered by default.

Binary file added YaleFaceDatabase/subject01.centerlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.glasses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.happy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.leftlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.noglasses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.normal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.rightlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.sad.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.sleepy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.surprised.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject01.wink.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.centerlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.glasses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.happy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.leftlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.noglasses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.normal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.rightlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.sad.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.sleepy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.surprised.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject02.wink.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject03.centerlight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject03.glasses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject03.happy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added YaleFaceDatabase/subject03.leftlight.gif
Binary file added YaleFaceDatabase/subject03.noglasses.gif
Binary file added YaleFaceDatabase/subject03.normal.gif
Binary file added YaleFaceDatabase/subject03.rightlight.gif
Binary file added YaleFaceDatabase/subject03.sad.gif
Binary file added YaleFaceDatabase/subject03.sleepy.gif
Binary file added YaleFaceDatabase/subject03.surprised.gif
Binary file added YaleFaceDatabase/subject03.wink.gif
Binary file added YaleFaceDatabase/subject04.centerlight.gif
Binary file added YaleFaceDatabase/subject04.glasses.gif
Binary file added YaleFaceDatabase/subject04.happy.gif
Binary file added YaleFaceDatabase/subject04.leftlight.gif
Binary file added YaleFaceDatabase/subject04.noglasses.gif
Binary file added YaleFaceDatabase/subject04.normal.gif
Binary file added YaleFaceDatabase/subject04.rightlight.gif
Binary file added YaleFaceDatabase/subject04.sad.gif
Binary file added YaleFaceDatabase/subject04.sleepy.gif
Binary file added YaleFaceDatabase/subject04.surprised.gif
Binary file added YaleFaceDatabase/subject04.wink.gif
Binary file added YaleFaceDatabase/subject05.centerlight.gif
Binary file added YaleFaceDatabase/subject05.glasses.gif
Binary file added YaleFaceDatabase/subject05.happy.gif
Binary file added YaleFaceDatabase/subject05.leftlight.gif
Binary file added YaleFaceDatabase/subject05.noglasses.gif
Binary file added YaleFaceDatabase/subject05.normal.gif
Binary file added YaleFaceDatabase/subject05.rightlight.gif
Binary file added YaleFaceDatabase/subject05.sad.gif
Binary file added YaleFaceDatabase/subject05.sleepy.gif
Binary file added YaleFaceDatabase/subject05.surprised.gif
Binary file added YaleFaceDatabase/subject05.wink.gif
Binary file added YaleFaceDatabase/subject06.centerlight.gif
Binary file added YaleFaceDatabase/subject06.glasses.gif
Binary file added YaleFaceDatabase/subject06.happy.gif
Binary file added YaleFaceDatabase/subject06.leftlight.gif
Binary file added YaleFaceDatabase/subject06.noglasses.gif
Binary file added YaleFaceDatabase/subject06.normal.gif
Binary file added YaleFaceDatabase/subject06.rightlight.gif
Binary file added YaleFaceDatabase/subject06.sad.gif
Binary file added YaleFaceDatabase/subject06.sleepy.gif
Binary file added YaleFaceDatabase/subject06.surprised.gif
Binary file added YaleFaceDatabase/subject06.wink.gif
Binary file added YaleFaceDatabase/subject07.centerlight.gif
Binary file added YaleFaceDatabase/subject07.glasses.gif
Binary file added YaleFaceDatabase/subject07.happy.gif
Binary file added YaleFaceDatabase/subject07.leftlight.gif
Binary file added YaleFaceDatabase/subject07.noglasses.gif
Binary file added YaleFaceDatabase/subject07.normal.gif
Binary file added YaleFaceDatabase/subject07.rightlight.gif
Binary file added YaleFaceDatabase/subject07.sad.gif
Binary file added YaleFaceDatabase/subject07.sleepy.gif
Binary file added YaleFaceDatabase/subject07.surprised.gif
Binary file added YaleFaceDatabase/subject07.wink.gif
Binary file added YaleFaceDatabase/subject08.centerlight.gif
Binary file added YaleFaceDatabase/subject08.glasses.gif
Binary file added YaleFaceDatabase/subject08.happy.gif
Binary file added YaleFaceDatabase/subject08.leftlight.gif
Binary file added YaleFaceDatabase/subject08.noglasses.gif
Binary file added YaleFaceDatabase/subject08.normal.gif
Binary file added YaleFaceDatabase/subject08.rightlight.gif
Binary file added YaleFaceDatabase/subject08.sad.gif
Binary file added YaleFaceDatabase/subject08.sleepy.gif
Binary file added YaleFaceDatabase/subject08.surprised.gif
Binary file added YaleFaceDatabase/subject08.wink.gif
Binary file added YaleFaceDatabase/subject09.centerlight.gif
Binary file added YaleFaceDatabase/subject09.glasses.gif
Binary file added YaleFaceDatabase/subject09.happy.gif
Binary file added YaleFaceDatabase/subject09.leftlight.gif
Binary file added YaleFaceDatabase/subject09.noglasses.gif
Binary file added YaleFaceDatabase/subject09.normal.gif
Binary file added YaleFaceDatabase/subject09.rightlight.gif
Binary file added YaleFaceDatabase/subject09.sad.gif
Binary file added YaleFaceDatabase/subject09.sleepy.gif
Binary file added YaleFaceDatabase/subject09.surprised.gif
Binary file added YaleFaceDatabase/subject09.wink.gif
Binary file added YaleFaceDatabase/subject10.centerlight.gif
Binary file added YaleFaceDatabase/subject10.glasses.gif
Binary file added YaleFaceDatabase/subject10.happy.gif
Binary file added YaleFaceDatabase/subject10.leftlight.gif
Binary file added YaleFaceDatabase/subject10.noglasses.gif
Binary file added YaleFaceDatabase/subject10.normal.gif
Binary file added YaleFaceDatabase/subject10.rightlight.gif
Binary file added YaleFaceDatabase/subject10.sad.gif
Binary file added YaleFaceDatabase/subject10.sleepy.gif
Binary file added YaleFaceDatabase/subject10.surprised.gif
Binary file added YaleFaceDatabase/subject10.wink.gif
Binary file added YaleFaceDatabase/subject11.centerlight.gif
Binary file added YaleFaceDatabase/subject11.glasses.gif
Binary file added YaleFaceDatabase/subject11.happy.gif
Binary file added YaleFaceDatabase/subject11.leftlight.gif
Binary file added YaleFaceDatabase/subject11.noglasses.gif
Binary file added YaleFaceDatabase/subject11.normal.gif
Binary file added YaleFaceDatabase/subject11.rightlight.gif
Binary file added YaleFaceDatabase/subject11.sad.gif
Binary file added YaleFaceDatabase/subject11.sleepy.gif
Binary file added YaleFaceDatabase/subject11.surprised.gif
Binary file added YaleFaceDatabase/subject11.wink.gif
Binary file added YaleFaceDatabase/subject12.centerlight.gif
Binary file added YaleFaceDatabase/subject12.glasses.gif
Binary file added YaleFaceDatabase/subject12.happy.gif
Binary file added YaleFaceDatabase/subject12.leftlight.gif
Binary file added YaleFaceDatabase/subject12.noglasses.gif
Binary file added YaleFaceDatabase/subject12.normal.gif
Binary file added YaleFaceDatabase/subject12.rightlight.gif
Binary file added YaleFaceDatabase/subject12.sad.gif
Binary file added YaleFaceDatabase/subject12.sleepy.gif
Binary file added YaleFaceDatabase/subject12.surprised.gif
Binary file added YaleFaceDatabase/subject12.wink.gif
Binary file added YaleFaceDatabase/subject13.centerlight.gif
Binary file added YaleFaceDatabase/subject13.glasses.gif
Binary file added YaleFaceDatabase/subject13.happy.gif
Binary file added YaleFaceDatabase/subject13.leftlight.gif
Binary file added YaleFaceDatabase/subject13.noglasses.gif
Binary file added YaleFaceDatabase/subject13.normal.gif
Binary file added YaleFaceDatabase/subject13.rightlight.gif
Binary file added YaleFaceDatabase/subject13.sad.gif
Binary file added YaleFaceDatabase/subject13.sleepy.gif
Binary file added YaleFaceDatabase/subject13.surprised.gif
Binary file added YaleFaceDatabase/subject13.wink.gif
Binary file added YaleFaceDatabase/subject14.centerlight.gif
Binary file added YaleFaceDatabase/subject14.glasses.gif
Binary file added YaleFaceDatabase/subject14.happy.gif
Binary file added YaleFaceDatabase/subject14.leftlight.gif
Binary file added YaleFaceDatabase/subject14.noglasses.gif
Binary file added YaleFaceDatabase/subject14.normal.gif
Binary file added YaleFaceDatabase/subject14.rightlight.gif
Binary file added YaleFaceDatabase/subject14.sad.gif
Binary file added YaleFaceDatabase/subject14.sleepy.gif
Binary file added YaleFaceDatabase/subject14.surprised.gif
Binary file added YaleFaceDatabase/subject14.wink.gif
Binary file added YaleFaceDatabase/subject15.centerlight.gif
Binary file added YaleFaceDatabase/subject15.glasses.gif
Binary file added YaleFaceDatabase/subject15.happy.gif
Binary file added YaleFaceDatabase/subject15.leftlight.gif
Binary file added YaleFaceDatabase/subject15.noglasses.gif
Binary file added YaleFaceDatabase/subject15.normal.gif
Binary file added YaleFaceDatabase/subject15.rightlight.gif
Binary file added YaleFaceDatabase/subject15.sad.gif
Binary file added YaleFaceDatabase/subject15.sleepy.gif
Binary file added YaleFaceDatabase/subject15.surprised.gif
Binary file added YaleFaceDatabase/subject15.wink.gif
Binary file added images/avg.png
Binary file added images/cm.png
Binary file added images/correct.png
Binary file added images/correct.png.png
Binary file added images/covariance.png
Binary file added images/ef.png
Binary file added images/eigen.png
Binary file added images/img1.png
Binary file added images/minus.png
Binary file added images/weights.png
Binary file added images/wrong.png
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy
matplotlib
sklearn

0 comments on commit e48fe69

Please sign in to comment.