public void StatisticWrite(string FileName, string AViFileName, string TXtFileName)
        {
            // Create the new, empty data file.
            FileStream fs = new FileStream(FileName, FileMode.CreateNew);
            // Create the writer for data.
            BinaryWriter w = new BinaryWriter(fs);
            // Write data to Test.data.

            //Open AVI file to read all frames
            avi_reader.Open(AViFileName);

            avi_writer.Open("DSP.avi", avi_reader.width, avi_reader.height);
            //Recalculate stat structure to holld all frames statistis
            //	StatisticalData [] stat = new StatisticalData[avi_reader.length];
            FileLenght = avi_reader.length;
            stat = new StatisticalData[FileLenght];

            string str = "";
            StatisticalData stat1 = new StatisticalData();

            //Open window to show opened frames
            //		FormLoaded = new frmLoaded();
             //       FormLoaded.Show();
            int count = 0;
            Cursor.Current = Cursors.WaitCursor;
            for (int i = 0; i < FileLenght; i++)
            {
                if(bmpTmp != null)
                    bmpTmp.Dispose();
               bmpTmp = avi_reader.GetNextFrame();
               avi_writer.AddFrame(bmpTmp);

               imagestatistic.ImageStreamStatistic(bmpTmp);
                //Here we can add DSP features
                //Visualize frames

            //       if (count > 10)
            //       {
            //          count = 0;
            //           FormLoaded.LoadBitmap(bmpTmp);
            //       }
               //       count++;

                stat[i] = imagestatistic.StatisticDataa;
                stat1 = stat[i];
            //		str = str + ";" + i.ToString();
                w.Write(stat1.mean);
                w.Write(stat1.sigma);
                w.Write(stat1.K);
                w.Write(stat1.P);
                w.Write(stat1.Z);

            }
            avi_reader.Close();
            avi_writer.Close();

              //      FormLoaded.LoadBitmap(bmpTmp);

            //Close preview window
             //   FormLoaded.Close();
            //	MessageBox.Show("Writed data is: " + str);
            str.Remove(0,str.Length);
            w.Close();
            fs.Close();

            StatisticWriteTXT(TXtFileName);
        }
 private void StatisticWriteTXT(string FileName)
 {
     using (StreamWriter sw = new StreamWriter(FileName))
     {
     //	StatisticalData [] stat = new StatisticalData[FileLenght];
         StatisticalData stat1 = new StatisticalData();
         string str = "";
         for (int i = 0; i < FileLenght; i++)
         {
         //	stat[i].K = (double) 100;
             str = "Frm " + i.ToString() + ";";
             str = str + stat[i].mean.ToString() + ";";
             str = str + stat[i].sigma.ToString() + ";";
             str = str + stat[i].K.ToString() + ";";
             str = str + stat[i].P.ToString() + ";";
             str = str + stat[i].Z.ToString();
             sw.WriteLine(str);
             str = "";
         }
         // Add some text to the file.
         sw.WriteLine("-------------------");
         sw.WriteLine("mean;sigma;K;P;Z");
         // Arbitrary objects can also be written to the file.
         sw.Write("File Created: ");
         sw.WriteLine(DateTime.Now);
     }
 }