/// <summary> /// Function used to get top FaceRecognition.Properties.Settings.Default.DReductionVal Image vectors /// </summary> /// <param name="OriginalEigenVector"></param> /// <param name="EigenVectorForImage"></param> public void GetTopEigenVectors(PCALib.IMatrix OriginalEigenVector, ref double[][] EigenVectorForImage) { for (int iRow = 0; iRow < OriginalEigenVector.Rows; iRow++) { for (int iColumn = 0; iColumn < PCA_App.Properties.Settings.Default.DReductionVal; iColumn++) { if (iColumn == 0) { EigenVectorForImage[iRow] = new double[PCA_App.Properties.Settings.Default.DReductionVal]; } EigenVectorForImage[iRow][iColumn] = new double(); EigenVectorForImage[iRow][iColumn] = OriginalEigenVector[iRow, iColumn]; } } }
void GetImageMatrix() { //Code for Intializing Matrix MainImageMatrix_forAllImages = new double[1][]; double[][] MainImageMatrix_Covariance = new double[1][]; CopyImageMatrix_forallImages = new double[1][]; //InitializeMatrix_1(ref MainImageMatrix); // Call function to fetch all image in a matrix format //Get data image from "Data" folder to an array (first dimension is pixel value, second dimension is image index) _objMatrix.InitializeMatrix(ref MainImageMatrix_forAllImages); // just copy from "MainImageMatrix_forAllImages" to "CopyImageMatrix_forallImages" _objMatrix.CopyMatrix(MainImageMatrix_forAllImages, ref CopyImageMatrix_forallImages); //Code for finding means vector from the MainImage Matrix MeanVector = new double[1][]; // calculate the mean value of pixel value for each image MeanVector = _objMatrix.GetMeanVector(ref MainImageMatrix_forAllImages); //Performing Step 2 of Algorithm _objMatrix.getMeanAdjustedMatrix(ref MainImageMatrix_forAllImages, MeanVector); //Compute Covariance matrix MainImageMatrix_Covariance = _objMatrix.getCovarianceMatrix(MainImageMatrix_forAllImages); //Computing Eigen values and Eigen vecotors by suding MaPack library PCALib.Matrix obj = new Matrix(MainImageMatrix_Covariance); IEigenvalueDecomposition EigenVal; EigenVal = obj.GetEigenvalueDecomposition(); // Take only top 10 eigen values double[] EigenValforImage = new double[PCA_App.Properties.Settings.Default.DReductionVal]; double[][] TransposevalImage = new double[PCA_App.Properties.Settings.Default.DReductionVal][]; EigenFaceImage = new double[PCA_App.Properties.Settings.Default.DReductionVal][]; EigenVectorforImage = new double[PCA_App.Properties.Settings.Default.DefaultNumberOfImages][]; // double[][] PixelmatrixforImage = new double[FaceRecognition.Properties.Settings.Default.DefaultNumberOfImages][]; _objMatrix.GetTopEigenValues(EigenVal.RealEigenvalues, ref EigenValforImage); // Taking top 10 Eigen vectors PCALib.IMatrix EigenVector = EigenVal.EigenvectorMatrix; _objMatrix.GetTopEigenVectors(EigenVector, ref EigenVectorforImage); // _objMatrix.Transpose(CopyImageMatrix, ref TransposevalImage); _objMatrix.Multiply(MainImageMatrix_forAllImages, EigenVectorforImage, ref EigenFaceImage); // Transpose the Eigen Face images so that we can use inbuilt max and min function in array. _objMatrix.Transpose(EigenFaceImage, ref TransposevalImage, PCA_App.Properties.Settings.Default.DReductionVal); double[][] PixelmatrixforImage = new double[PCA_App.Properties.Settings.Default.DReductionVal][]; _objMatrix.ConvertinPixelScale(TransposevalImage, ref PixelmatrixforImage, EigenFaceImage.Length); // _objMatrix.Transpose(PixelmatrixforImage, ref TransposevalImage,EigenFaceImage.Length); //int iControl = 0; /* foreach (Control cobj in gbxImages.Controls) * { * if (cobj is PictureBox) * { * cobj.BackgroundImage = _objMatrix.DrawFaceValue(PixelmatrixforImage, iControl); * iControl++; * } * * }*/ BaseMatrix = new double[clsMatrixOperation.iDefaultImageCount][]; double[][] ProductMatrix = null; double[][] Transponse_EachImage = new double[PCA_App.Properties.Settings.Default.DReductionVal][]; for (int irow = 0; irow < clsMatrixOperation.iDefaultImageCount; irow++) { Transponse_EachImage = new double[EigenFaceImage.Length][]; _objMatrix.Transpose(MainImageMatrix_forAllImages, ref Transponse_EachImage, 1, irow + 1); _objMatrix.Multiply(Transponse_EachImage, EigenFaceImage, ref ProductMatrix); for (int iColumn = 0; iColumn < clsMatrixOperation.iDimensionalReduction; iColumn++) { if (iColumn == 0) { BaseMatrix[irow] = new double[clsMatrixOperation.iDimensionalReduction]; } BaseMatrix[irow][iColumn] = new double(); BaseMatrix[irow][iColumn] = ProductMatrix[0][iColumn]; } } // _objMatrix.Multiply(CopyImageMatrix, EigenFaceImage, ref BaseMatrix); }