I have a windows forms project and I have a dataset called the ATTDataSet
, the folder has two folders, the training
and testing
folders, each contain similar images in the same order. I have a form with two picture box with the labels original image
and recognized image
. I need help with processing an image from the training folder to train this program to save the name of that image and identify a similar image in the testing folder with this algorithm Linear Discriminant Analysis
. I want to train the program first to learn a face and then later I will implement a button handler to identify all the images in the second folder with the same pattern as that which was recognized in the learn process. The code am using is below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace LDA_FaceR
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//read the first image in the ATT data set folder
string path = "C://Users//TimothyFarCry5//Documents//visual studio 2015//Projects//LDA-FaceR//LDA-FaceR//ATTDataSet//Training//S1_1.jpg";
Bitmap mymap = new Bitmap(Image.FromFile(path));
pictureBox1.Image = mymap;
//program so that the program intitiates an LDA sequence to learn the image
}
//this method tries to identify images from the second testing folder with the LDA
//pattern stored in the learn process, please help
private void button2_Click(object sender, EventArgs e)
{
}
}
}
Update
After digging online a little, I learned that I need to use classes to do this and I need to express the images in the database as a one dimesnion vector and then I should compute the mean and then subtract the mean from all images and then get eigenfaces. How do I express an image in the format shown below? The images have been expressed in vector form, how to do this is the problem and then later I can try to compute the mean.
This project is really important, Kudos to all who are willing to help.
You would need at least some linear algebra library which can compute vector-matrix multiplication and an inverse of a matrix. In such case you compute covariance of all your data, take it's inverse, and the discriminative vector is then a vector between means (centers) of two classes multiplied by the inverse.
There are libraries which implement LDA. For example Egmu CV (which is sort of OpenCV in C#) has FisherFaceRecognizer which should implement Fischer Discriminant Analysis which is almost exactly LDA (the differences are not important). https://www.emgu.com/wiki/files/4.5.1/document/html/80c70818-c4e1-e5a7-6c74-1ce3d6bd1be4.htm
Anyway, LDA for face recognition is not a good idea and it will not work much (almost at all). Reasonable approach is to take a CNN specifically trained to extract facial embeddings and compare those embedding using simple distance function (e.g. L2) to get a facial identity distance of images. Many "deep learning" frameworks can be used from C# and you can download pretrained face recognition networks.