SlideShare a Scribd company logo
A quick walkthrough and sample
implementation of the Eigenfaces
algorithm in Scala.
Justin Long
What is Eigenfaces?
Need to do quick and dirty object or facial recognition?
Eigenfaces may be for you.
The essence of Eigenfaces
Eigenfaces is the name given to a set of
eigenvectors when they are used for facial
recognition.
A typical use for calculating Eigenfaces works as such:
1. Obtain a training set of faces and convert to a pixel matrix
2. Compute the mean image (which is an average of pixel
intensity across each image).
3. Compute a differential matrix by subtracting the mean from
each training image, pixel by pixel
4. Compute covariance matrix of the differential matrix
The essence of Eigenfaces
Your “average face” may look a little
uncanny…
4. Calculate eigenvectors from covariance matrix
5. Compute Eigenfaces by multiplying eigenvectors and
covariance matrices together, and normalizing them
Putting it together
def computeEigenFaces(pixelMatrix: Array[Array[Double]], meanColumn:
Array[Double]): DoubleMatrix2D = {
val diffMatrix = MatrixHelpers.computeDifferenceMatrixPixels(pixelMatrix,
meanColumn)
val covarianceMatrix = MatrixHelpers.computeCovarianceMatrix(pixelMatrix,
diffMatrix)
val eigenVectors = MatrixHelpers.computeEigenVectors(covarianceMatrix)
computeEigenFaces(eigenVectors, diffMatrix)
}
Multiplying eigenvectors/differential
(0 to (rank-1)).foreach { i =>
var sumSquare = 0.0
(0 to (pixelCount-1)).foreach { j =>
(0 to (imageCount-1)).foreach { k =>
eigenFaces(j)(i) += diffMatrix(j)(k) * eigenVectors.get(i,k)
}
sumSquare += eigenFaces(j)(i) * eigenFaces(j)(i)
}
var norm = Math.sqrt(sumSquare)
(0 to (pixelCount-1)).foreach { j =>
eigenFaces(j)(i) /= norm
}
}
Preprocessing is key
You need to preprocess your images!
- Grayscale: important for calculating proper pixel intensity values
- Normalization: very helpful if your images were taken in different
lighting conditions
- Cropping: Very important to focus only on facial features
Without preprocessing, you’re gonna have a bad time.
Potential for Eigenfaces?
Facial recognition is most obvious use.
Eigenfaces and eigenvectors are also useful for other
applications of computer vision:
- Subjects that can be read 2-dimensionally, from same angle
- Optical Character Recognition (OCR)
- Image segmentation
- http://www.cs.huji.ac.il/~yweiss/iccv99.pdf
What about this author?
Well… I had a more creative use for
Eigenfaces…
Tinderbox used Eigenfaces
What happened when I got fed up with all the swiping involved in
Tinder? I automated it with Eigenfaces (a slightly modified
strategy).
- Added a simple step of averaging all faces together for yes/no
faces
- The “average” face was used for Eigenfaces selection (k-nearest
neighbor between 2 models)
A quick look at Tinderbox
http://crockpotveggies.com/2015/02/09/automating-tinder-with-
eigenfaces.html
Questions?

More Related Content

PPTX
Face Recognition
PPTX
Face Recognition using PCA-Principal Component Analysis using MATLAB
PPTX
Face recognition vaishali
PPTX
Java fx 3d
PPTX
face recognition based on PCA
PPTX
Face recogntion Using PCA Algorithm
PDF
Lec14 eigenface and fisherface
PPTX
Face recognition using PCA
Face Recognition
Face Recognition using PCA-Principal Component Analysis using MATLAB
Face recognition vaishali
Java fx 3d
face recognition based on PCA
Face recogntion Using PCA Algorithm
Lec14 eigenface and fisherface
Face recognition using PCA

What's hot (12)

PPTX
3D Graphics & Rendering in Computer Graphics
PPTX
Hog and sift
PDF
Differentiable Ray Sampling for Neural 3D Representation
PDF
Artificial neural network
PDF
Structure and Motion - 3D Reconstruction of Cameras and Structure
PDF
sdcSpatial user!2019
PPTX
Mathematical operations in image processing
PDF
Weakly supervised semantic segmentation of 3D point cloud
PDF
Introduction to 3D Computer Vision and Differentiable Rendering
PDF
T01022103108
3D Graphics & Rendering in Computer Graphics
Hog and sift
Differentiable Ray Sampling for Neural 3D Representation
Artificial neural network
Structure and Motion - 3D Reconstruction of Cameras and Structure
sdcSpatial user!2019
Mathematical operations in image processing
Weakly supervised semantic segmentation of 3D point cloud
Introduction to 3D Computer Vision and Differentiable Rendering
T01022103108
Ad

Viewers also liked (11)

PDF
Scala for Machine Learning
PDF
Image Classification and Retrieval on Spark
PPTX
Machine Learning With Spark
PPTX
Stock Market Prediction using Hidden Markov Models and Investor sentiment
PDF
Interactive Scientific Image Analysis using Spark
PPTX
Smart Data Conference: DL4J and DataVec
PDF
MLlib: Spark's Machine Learning Library
PDF
Introduction to Machine Learning with Spark
PDF
Sparkly Notebook: Interactive Analysis and Visualization with Spark
PPTX
Top 5 Deep Learning and AI Stories 1/27
PPT
Hidden Markov Model & Stock Prediction
Scala for Machine Learning
Image Classification and Retrieval on Spark
Machine Learning With Spark
Stock Market Prediction using Hidden Markov Models and Investor sentiment
Interactive Scientific Image Analysis using Spark
Smart Data Conference: DL4J and DataVec
MLlib: Spark's Machine Learning Library
Introduction to Machine Learning with Spark
Sparkly Notebook: Interactive Analysis and Visualization with Spark
Top 5 Deep Learning and AI Stories 1/27
Hidden Markov Model & Stock Prediction
Ad

Similar to Eigenfaces In Scala (20)

PPTX
Face Recognition using Eigen Values pptx
PPT
Eigenface For Face Recognition
PDF
Eigenfaces
PPT
L008.Eigenfaces And Nn Som
PDF
Ijebea14 276
PDF
Project 2
PDF
Face Recognition for Different Facial Expressions Using Principal Component a...
PDF
Image Similarity Test Using Eigenface Calculation
PDF
Solr and Machine Vision - Scott Cote, Lucidworks & Trevor Grant, IBM
PPTX
PCA Based Face Recognition System
PDF
Tracking Faces using Active Appearance Models
PPT
A study on face recognition technique based on eigenface
PDF
Harris corner detector and face recognition
PDF
K044065257
PPTX
Automated attendance system based on facial recognition
PDF
Design of face recognition system using principal
PDF
Face recognition and deep learning โดย ดร. สรรพฤทธิ์ มฤคทัต NECTEC
PDF
A017530114
PPTX
Eigenfaces , Fisherfaces and Dimensionality_Reduction
PDF
Face Recognition using Eigen Values pptx
Eigenface For Face Recognition
Eigenfaces
L008.Eigenfaces And Nn Som
Ijebea14 276
Project 2
Face Recognition for Different Facial Expressions Using Principal Component a...
Image Similarity Test Using Eigenface Calculation
Solr and Machine Vision - Scott Cote, Lucidworks & Trevor Grant, IBM
PCA Based Face Recognition System
Tracking Faces using Active Appearance Models
A study on face recognition technique based on eigenface
Harris corner detector and face recognition
K044065257
Automated attendance system based on facial recognition
Design of face recognition system using principal
Face recognition and deep learning โดย ดร. สรรพฤทธิ์ มฤคทัต NECTEC
A017530114
Eigenfaces , Fisherfaces and Dimensionality_Reduction

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
A Presentation on Artificial Intelligence
PPTX
Machine Learning_overview_presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
sap open course for s4hana steps from ECC to s4
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
MYSQL Presentation for SQL database connectivity
A Presentation on Artificial Intelligence
Machine Learning_overview_presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
sap open course for s4hana steps from ECC to s4

Eigenfaces In Scala

  • 1. A quick walkthrough and sample implementation of the Eigenfaces algorithm in Scala. Justin Long
  • 2. What is Eigenfaces? Need to do quick and dirty object or facial recognition? Eigenfaces may be for you.
  • 3. The essence of Eigenfaces Eigenfaces is the name given to a set of eigenvectors when they are used for facial recognition. A typical use for calculating Eigenfaces works as such: 1. Obtain a training set of faces and convert to a pixel matrix 2. Compute the mean image (which is an average of pixel intensity across each image). 3. Compute a differential matrix by subtracting the mean from each training image, pixel by pixel 4. Compute covariance matrix of the differential matrix
  • 4. The essence of Eigenfaces Your “average face” may look a little uncanny… 4. Calculate eigenvectors from covariance matrix 5. Compute Eigenfaces by multiplying eigenvectors and covariance matrices together, and normalizing them
  • 5. Putting it together def computeEigenFaces(pixelMatrix: Array[Array[Double]], meanColumn: Array[Double]): DoubleMatrix2D = { val diffMatrix = MatrixHelpers.computeDifferenceMatrixPixels(pixelMatrix, meanColumn) val covarianceMatrix = MatrixHelpers.computeCovarianceMatrix(pixelMatrix, diffMatrix) val eigenVectors = MatrixHelpers.computeEigenVectors(covarianceMatrix) computeEigenFaces(eigenVectors, diffMatrix) }
  • 6. Multiplying eigenvectors/differential (0 to (rank-1)).foreach { i => var sumSquare = 0.0 (0 to (pixelCount-1)).foreach { j => (0 to (imageCount-1)).foreach { k => eigenFaces(j)(i) += diffMatrix(j)(k) * eigenVectors.get(i,k) } sumSquare += eigenFaces(j)(i) * eigenFaces(j)(i) } var norm = Math.sqrt(sumSquare) (0 to (pixelCount-1)).foreach { j => eigenFaces(j)(i) /= norm } }
  • 7. Preprocessing is key You need to preprocess your images! - Grayscale: important for calculating proper pixel intensity values - Normalization: very helpful if your images were taken in different lighting conditions - Cropping: Very important to focus only on facial features Without preprocessing, you’re gonna have a bad time.
  • 8. Potential for Eigenfaces? Facial recognition is most obvious use. Eigenfaces and eigenvectors are also useful for other applications of computer vision: - Subjects that can be read 2-dimensionally, from same angle - Optical Character Recognition (OCR) - Image segmentation - http://www.cs.huji.ac.il/~yweiss/iccv99.pdf
  • 9. What about this author? Well… I had a more creative use for Eigenfaces…
  • 10. Tinderbox used Eigenfaces What happened when I got fed up with all the swiping involved in Tinder? I automated it with Eigenfaces (a slightly modified strategy). - Added a simple step of averaging all faces together for yes/no faces - The “average” face was used for Eigenfaces selection (k-nearest neighbor between 2 models)
  • 11. A quick look at Tinderbox http://crockpotveggies.com/2015/02/09/automating-tinder-with- eigenfaces.html