public static double[,] reconstruct(double[] weights, double[][,] eigFaces, double[,] avg) { int length = eigFaces[0].GetLength(0); double[,] result = new double[length, length]; //normalize(weights); for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { for (int k = 0; k < eigFaces.Length; k++) { result[i, j] += eigFaces[k][i, j] * weights[k] / eigFaces.Length; } } } ImageTool.normalize(result, 128); for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { result[i, j] += avg[i, j]; } } return(result); }
private void MainForm_Load(object sender, EventArgs e) { mainBmp = new Bitmap(Image.FromFile("./plane.bmp")); pb_main.Image = mainBmp; double[,] img = ImageTool.GetGreyScale(mainBmp); ImageTool.SetImage(mainBmp, img); int libCount = LoadLibrary("./imgLib", mainBmp.Width, mainBmp.Height, FACES_PER_PERSON); avg = ImageTool.GetAvg(lib); difLib = ImageTool.GetDifferenceArray(lib, avg); sb_lib.Maximum = libCount; libBmp = new Bitmap(mainBmp.Width, mainBmp.Height); EigenObject eigVects = ImageTool.GetEigen(ImageTool.GetA(lib)); ImageTool.normalize(eigVects.vectors); eigFaces = ImageTool.getEigenFaces(eigVects.vectors, difLib); libWeights = new double[lib.Length][]; for (int i = 0; i < lib.Length; i++) { libWeights[i] = ImageTool.getWeights(eigFaces, lib[i], avg); } double[] weights = ImageTool.getWeights(eigFaces, img, avg); comp = ImageTool.compareWeigths(libWeights, weights); int p = ImageTool.smallestVal(comp); lb_person.Text = "Person: " + p; recon = ImageTool.reconstruct(weights, eigFaces, avg); ImageTool.normalize(recon, 255); pb_lib.Image = libBmp; ImageTool.SetImage(libBmp, lib[p]); sb_lib.Value = p; }
public FaceRecog() { mainBmp = new Bitmap(Image.FromFile("./plane.bmp")); //Would be picturebox of compared image. //pb_main.Image = mainBmp; double[,] img = ImageTool.GetGreyScale(mainBmp); ImageTool.SetImage(mainBmp, img); int libCount = LoadLibrary("./imgLib", mainBmp.Width, mainBmp.Height, FACES_PER_PERSON); avg = ImageTool.GetAvg(lib); difLib = ImageTool.GetDifferenceArray(lib, avg); //Would be scrollbar //sb_lib.Maximum = libCount; libBmp = new Bitmap(mainBmp.Width, mainBmp.Height); EigenObject eigVects = ImageTool.GetEigen(ImageTool.GetA(lib)); ImageTool.normalize(eigVects.vectors); eigFaces = ImageTool.getEigenFaces(eigVects.vectors, difLib); libWeights = new double[lib.Length][]; for (int i = 0; i < lib.Length; i++) { libWeights[i] = ImageTool.getWeights(eigFaces, lib[i], avg); } double[] weights = ImageTool.getWeights(eigFaces, img, avg); comp = ImageTool.compareWeigths(libWeights, weights); int p = ImageTool.smallestVal(comp); //Would be guess of face //lb_person.Text = "Person: " + p; recon = ImageTool.reconstruct(weights, eigFaces, avg); ImageTool.normalize(recon, 255); //would be displaying the image. //pb_lib.Image = libBmp; ImageTool.SetImage(libBmp, lib[p]); //Would be setting scrollbar to correct position //sb_lib.Value = p; }