Am trying to implement face detection using the PCA algorithm in C#,I have a button on my windows forms that is supposed to intitiate the learning process once it is clicked. It should use the images in a folder called training to compute the eigen values and eigen vectors so that it would be able to identify a similar image from the test folder. I have loaded all the 200 images in the training folder into an array list and now my problem is converting this collection of images to a one dimension vector so that i can be able to compute the co-variance matrix and eigen values for it. My code is listed below, if there is any way my code can be improved then your corrections are welcome

namespace PCA
{
    public partial class Form1 : Form
    {
        //the mapack library has been used to create new instances of the matrices
        //hold the width and height of an image in a variable
        static int height = 112;
        static int width = 92;
        //store the number of train images in a variable
        static int train_images = 200;
        //store the number of eigen values to keep in a variable
        static int eigen_values = 50;
        //initialize the matrix data
        PCALib.Matrix matrix_data = new PCALib.Matrix(train_images, width * height);
        //initialize the Target matrix data
        PCALib.Matrix T = new PCALib.Matrix(train_images,eigen_values);
        //initialize the mean of the images
        int image_mean = 0;
        //initialize the image array 
        List<Image> training = new List<Image>();
        //the path to the images
        static string path = "C:/Users/TimothyFarCry5/Documents/visual studio 2015/Projects/PCA/PCA/training";
        public Form1()
        {
            InitializeComponent();
        }
        //the method below starts the training process
        private void button1_Click(object sender, EventArgs e)
        {
            /*read all the images in the training folder into an array
            in this case the images are already in gray scale so we do not need to convert
            */
            var files = Directory.GetFiles(path);
            foreach(string r in files)
            {
                if(Regex.IsMatch(r, @"\.jpg$|\.png$|\.gif$"))
                {
                    training.Add(Image.FromFile(r));
                }
            }
            //convert the list of images to a one dimension vector
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.