private void button22_Click(object sender, EventArgs e) { //сперва посчитать СВ //static public double[] averange_img = null; //public static double[,] eigenfaces = null; //[ размерность фотки , число фоток] coefficient += 5; int counter1 = PCA_for_images.averange_img.GetLength(0); int counter2 = PCA_for_images.eigenfaces.GetLength(1); double[,] result_img = new double[counter1, 1]; for (int i = 0; i < counter1; i++) { result_img[i, 0] = PCA_for_images.averange_img[i] + coefficient * PCA_for_images.eigenfaces[i, num_of_PC]; } Bitmap[] btm = PCA_for_images.ByteToBitmap(result_img); pictureBox2.Image = PCA_for_images.ChangeBitmapSize(btm[0], 160, 190); }
private void button23_Click(object sender, EventArgs e) { //сперва посчитать СВ int counter1 = PCA_for_images.averange_img.GetLength(0); int counter2 = PCA_for_images.eigenfaces.GetLength(1); double[,] result_img = new double[counter1, 1]; double sum; for (int i = 0; i < counter1; i++) { sum = 0; for (int j = 0; j < counter2; j++) { sum += Math.Abs(PCA_for_images.eigenfaces[i, j]); } result_img[i, 0] = sum < 127.5 * counter2 ? 255 : 0; // из-за растяжения у меня ноль на 127,5 } Bitmap[] btm = PCA_for_images.ByteToBitmap(result_img); pictureBox3.Image = PCA_for_images.ChangeBitmapSize(btm[0], 160, 190); }
private void button1_Click(object sender, EventArgs e) { string mainPath = //"C:\\Users\\Amigo's\\Desktop\\pic\\PCA_test\\compiled\\wrap1"; //TODO для сравнения между выборками "C:\\Users\\Amigo's\\Desktop\\recogn\\training_images"; //TODO для распознавания //"C:\\Users\\Amigo's\\Desktop\\pic\\wrap"; //TODO набор монгол string[] paths = Directory.GetFiles(mainPath); eigenfaces = PCA_for_images.Pca(PCA_for_images.BitmapToByte(paths)); //TODO сделать проверку на равенство пикселей //TODO СВ можно взять левым вектором. тогда немного св будут четче.. но вроде проекции такие же pictureBox1.Width = 160; pictureBox1.Height = 190; PixelClasterization.SuperSave(PCA_for_images.aver_img_btm[0], "C:\\Users\\Amigo's\\Desktop\\eigenfaces\\resultAverangeImg.jpg"); pictureBox1.Image = PCA_for_images.ChangeBitmapSize(PCA_for_images.aver_img_btm[0], 160, 190); #region pca_testing /* * double[,] x = * { * {1.2, 2.3, 7, 10}, * {2 , 5, 4.2, 1.4}, * {3, 6, 9, 12} * }; * * #region standarize of x (входная переменная) * * double[] k = new double[nVars]; * double[] sigm = new double[nVars]; * for (int i = 0; i < nVars; i++) * { * k[i] = 0; * sigm[i] = 0; * } * * for (int i = 0; i < nPoints; i++) * { * for (int j = 0; j < nVars; j++) * { * k[j] += x[i, j]/nPoints; * } * }//среднее * * * for (int i = 0; i < nPoints; i++) * { * for (int j = 0; j < nVars; j++) * { * sigm[j] += Math.Pow(x[i, j] - k[j], 2)/nPoints; * } * * } * * for (int i = 0; i < nVars; i++) * { * sigm[i] = Math.Sqrt(sigm[i] * nPoints / (nPoints - 1)); * } * * * * * for (int i = 0; i < nPoints; i++) * { * for (int j = 0; j < nVars; j++) * { * x[i, j] = (x[i, j] - k[j]) / sigm[j]; * } * * } * * * * double[] eigen_values = new double[nVars]; * double[,] eigenvectors_matrix = new double[nVars, nVars]; //матрица собственных векторов, не понял почему на -1 умножено * alglib.pca.pcabuildbasis(x, nPoints, nVars, ref info, ref eigen_values, ref eigenvectors_matrix); * * var pca = new PrincipalComponentAnalysis(x, AnalysisMethod.Standardize); * pca.Compute(); * * var res = pca.Eigenvalues; * var res1 = pca.ComponentMatrix; * double[,] actual = pca.Transform(x,1); * * int k3 = 9; */ #endregion }