This project implements the concept of eigenfaces for facial recognition using MATLAB. It includes visualizations of the faces dataset, PCA to derive eigenfaces, and reconstructions of faces using a subset of eigenfaces.
- MATLAB
- Yale B dataset
allFaces.matfile (constructed from the Yale B dataset)
-
Download the Yale B Dataset:
- The dataset can be downloaded from Yale B Database.
-
Construct the
allFaces.matFile:- Extract the downloaded dataset.
- Convert the images into a matrix where each column represents a flattened image and save it as
allFaces.mat. - The
allFaces.matfile should contain the following variables:faces: A matrix where each column is a vectorized face image.nfaces: A vector containing the number of images per person.n: The height of each face image.m: The width of each face image.
This script visualizes the faces dataset and provides an overview of the data.
-
Load and Prepare Data:
- Loads the data from
allFaces.mat, containing faces of 38 individuals.
- Loads the data from
-
Display All Faces:
- Combines all faces into a single grid image and displays it.
- Figure 1: Shows the first image of each of the 36 training individuals under direct light.
-
Display Individual Faces:
- Displays different images taken from specific individuals under various lighting and angles.
- Figure 2: Visualizes several images for selected individuals.
The dataset is large, aiming to use SVD decomposition to learn how to reduce the dimensions of images with minimal cost and computations.
This script performs PCA on the facial data to derive eigenfaces and uses these eigenfaces for facial reconstruction and clustering.
-
Train Data:
- Uses the images of the first 36 individuals for training.
-
Compute Average Face:
- Calculates and displays the average face.
- Figure 1: Shows the average face of the training data.
-
Compute SVD:
- Subtracts the average from the data and computes SVD to get eigenfaces.
- Figure 2: Displays the first 50 eigenfaces calculated.
-
Face Reconstruction:
- Uses eigenfaces to reconstruct the face of a new individual (37th person).
- Figure 3: Shows the test face of the 37th individual.
- Figure 4: Reconstructs the face for various
rvalues, demonstrating how increasingrimproves the accuracy of the reconstructed image.
-
Face Clustering:
- Projects faces of two selected individuals into the PCA space and plots their coordinates to visualize clustering.
- Figure 5: Shows two faces (persons 2 and 7) that will be examined for clustering.
- Figure 6: Clusters the faces of the two individuals, showing that they can be distinctly identified.
-
eigenface_1.m- Loads and visualizes the faces dataset.
- Combines all faces into a single grid.
- Displays individual faces for each person in the dataset.
-
eigenface_2.m- Loads the faces dataset and computes the average face.
- Performs SVD to compute eigenfaces.
- Visualizes the average face and the first few eigenfaces.
- Reconstructs a test face using a varying number of eigenfaces.
- Projects specific faces into the PCA space and visualizes their coordinates.
- Ensure
allFaces.matis present in the directory. - The dataset should have variables for faces, number of faces (
nfaces), and their dimensions (n,m).
Enjoy working with eigenfaces! If you have any questions or issues, feel free to open an issue or contact me.