public void writeFeatureXML()
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent       = true;
            settings.NewLineChars = "\r\n";
            System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("C:\\major\\ProjectedPatterns.xml", settings);
            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Pattens");

            /*
             * for(int u=1;u<=5;u++)
             * {
             *  xmlWriter.WriteElementString("TotalPatterns"+u, Convert.ToString(5));
             * }
             * xmlWriter.WriteElementString("TotalPatterns11", Convert.ToString(5));
             *
             * int[] patOfFace = new int[10];
             * try
             * {
             *  Bitmap faceToProject = (Bitmap)Image.FromFile("C:\\major\\knownfaces\\1.jpg");
             *  FaceRecognition.searchDetected_ic(faceToProject);
             *  int[] patttt = FaceRecognition.getEudPat();
             *  for (int u = 1; u <= 10; u++)
             *  {
             *      xmlWriter.WriteElementString("TotalPatterns" + u, Convert.ToString(patttt[u - 1]));
             *  }
             * }
             *
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.Message);
             * }
             */


            //--------------------------------Known-----------------------------
            string faceFileLocationKnown = "C:\\major\\knownfaces\\";

            xmlWriter.WriteStartElement("KnownPatterns");
            for (int j = 1; j <= noOfKnownPatterns; j++)
            {
                string wrtStr = "KnownPattern" + Convert.ToString(j);
                xmlWriter.WriteStartElement(wrtStr);
                Bitmap faceToProject = (Bitmap)Image.FromFile(faceFileLocationKnown + "k" + j + ".jpg");

                //*********This will return first 10 minimum euclidian distances of the face stored in faceToProject****
                FaceRecognition.searchDetected_ic(faceToProject);
                int[] patOfFace = FaceRecognition.getEudPat();
                //*********

                //double[,] projectedFeatureRLDA = FaceRecognition.getRLdaFeatures(faceToProject);
                //for (int i = 0; i < projectedFeatureRLDA.GetLength(0); i++)
                //for (int i = 0; i < netSizeVCT; i++)//netSizeVCT is no of element in each pattern
                for (int i = 0; i < netSizeVCT; i++)//netSizeVCT is no of element in each pattern
                {
                    string s3      = "KnownPatternElement" + i;
                    string feature = Convert.ToString(patOfFace[i]);
                    xmlWriter.WriteElementString(s3, feature);
                }
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();
            //---------------------------------------------------------------------



            //--------------------------------Unknown-----------------------------
            string faceFileLocationUnknown = "C:\\major\\unknownfaces\\";

            xmlWriter.WriteStartElement("UnknownPatterns");
            for (int j = 1; j <= noOfUnknownPatterns; j++)
            {
                string wrtStr = "UnknownPattern" + Convert.ToString(j);
                xmlWriter.WriteStartElement(wrtStr);
                Bitmap faceToProject = (Bitmap)Image.FromFile(faceFileLocationUnknown + "NiD (" + j + ").jpg");

                //*********This will return first 10 minimum euclidian distances of the face stored in faceToProject****
                FaceRecognition.searchDetected_ic(faceToProject);
                int[] patOfFace = FaceRecognition.getEudPat();
                //*********

                //double[,] projectedFeatureRLDA = FaceRecognition.getRLdaFeatures(faceToProject);
                //for (int i = 0; i < projectedFeatureRLDA.GetLength(0); i++)
                for (int i = 0; i < netSizeVCT; i++)
                {
                    string s3      = "UnknownPatternElement" + i;
                    string feature = Convert.ToString(patOfFace[i]);
                    xmlWriter.WriteElementString(s3, feature);
                }
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();
            //---------------------------------------------------------------------


            xmlWriter.WriteEndElement();



            xmlWriter.Close();
        }
        public int recogn(Bitmap imgtrec)
        {
            int indel = 0;


            float tmean = 0; //mean of test image

            //float[,] testim;
            // final vector of the distance

            ImageProcessingUtilities.hist_equalize(imgtrec);
            //if (imgtrec.PixelFormat == PixelFormat.Format8bppIndexed)
            //{
            BitmapData bmData = imgtrec.LockBits(new Rectangle(0, 0, imgtrec.Width, imgtrec.Height), ImageLockMode.ReadWrite, imgtrec.PixelFormat);

            unsafe
            {
                int   j           = 0;
                byte *p           = (byte *)(void *)bmData.Scan0.ToPointer();
                int   stopAddress = (int)p + bmData.Stride * bmData.Height;
                //while ((int)p != stopAddress)
                while ((int)p != stopAddress)
                {
                    testIm[0, j] = p[0];
                    j++;
                    p++;
                }
                p = null;
                j = 0;
            }
            imgtrec.UnlockBits(bmData);

            //}


            /////////Deviation from mean////////////////////////
            //MessageBox.Show("stemp" + stemp.GetLength(0) + "," + stemp.GetLength(1) + "\n" + testIm.GetLength(0) + "," + testIm.GetLength(1));
            for (int i = 0; i < testIm.GetLength(1); i++)
            {
                tmean = tmean + testIm[0, i];
            }

            tmean /= testIm.GetLength(1);
            //MessageBox.Show(tmean.ToString());
            for (int i = 0; i < testIm.GetLength(1); i++)
            {
                testIm[0, i] = testIm[0, i] - tmean;
            }

            ///////// imgR*V   V=stemp///////////////////////

            //ThreadStart m1 = new ThreadStart(th1);
            //Thread mth1 = new Thread(m1);
            //mth1.Start();
            //ThreadStart m2 = new ThreadStart(th2);
            //Thread mth2 = new Thread(m2);
            //mth2.Start();


            //ThreadStart m3 = new ThreadStart(th3);
            //Thread mth3 = new Thread(m3);
            //mth3.Start();

            //testim = this.matmul(ref imgR, ref stemp);
            float sum1 = 0;

            dis_eu = new float[1, trainData / 4];
            for (int j = 0; j < (trainData / 4); j++)
            {
                sum1 = 0;
                for (int k = 0; k < testIm.GetLength(1); k++)
                {
                    sum1 += testIm[0, k] * stemp[k, j];
                }
                dis_eu[0, j] = sum1;
            }

            //MessageBox.Show("coordinate" + dis_eu[0, 0] + "," + dis_eu[0, 1] + "," + dis_eu[0, 2] + "," + dis_eu[0, 3] + ",");



            //this.savp("justy", testim);

            /*
             * double[,] rett = new double[testim.GetLength(0), testim.GetLength(1)];
             * for (int i = 0; i < rett.GetLength(0); i++)
             * {
             *
             *  for (int j = 0; j < rett.GetLength(1); j++)
             *      rett[i, j] = (double)testim[i, j];
             *
             * }
             */
            //MessageBox.Show("rc=(" + rc.GetLength(0) + "," + rc.GetLength(1)+")\n"+trainData);
            ///////////////recognition//////////////////////////
            double devsumsq = 0;

            el = new double[1, trainData];
            for (int i = 0; i < trainData; i++)
            {
                for (int j = 0; j < (trainData / 4); j++)
                {
                    devsumsq += Math.Pow((rc[i, j] - dis_eu[0, j]), 2);
                }
                el[0, i] = Math.Pow(devsumsq, .5);
                devsumsq = 0;
            }
            double min = el[0, 0];

            for (int i = 0; i < trainData; i++)
            {
                if (el[0, i] < min)
                {
                    min   = el[0, i];
                    indel = i;
                }
            }
            minEudDistance = (int)min;


            //MessageBox.Show("Index:"+indel.ToString());



            int classIndex;

            /*
             * if (min > 4500)
             * {
             *  indel = -1;
             *  MessageBox.Show("Unknown Face");
             * }
             */

            //else
            {
                classIndex = indel / 10;
                indel      = 1 + (indel / 10) * 10;
                //MessageBox.Show("min : " + Convert.ToString(min));
                double maxE = findMaxEuclidian();
                //MessageBox.Show("max : " + Convert.ToString(maxE));
                //MessageBox.Show("diff : " + Convert.ToString(maxE - min));
            }
            //this code will set the input vector for lvq

            /*
             * int inputVectorIndex=1;
             * LVQ.setInputVectors(minEudDistance, 0);
             * for (int i = indel; i < (indel + 5); i++)
             * {
             *  LVQ.setInputVectors((int)el[0,i], inputVectorIndex);
             *  inputVectorIndex++;
             * }
             */
            Sorter.BubbleSort(el);
            int[] pat = Sorter.getSortedPatterns();

            FaceRecognition.writeEudPat(pat);

            return(indel);
        }