Gather statistics about image in RGB color space.

The class is used to accumulate statistical values about images, like histogram, mean, standard deviation, etc. for each color channel in RGB color space.

The class accepts 8 bpp grayscale and 24/32 bpp color images for processing.

Sample usage:

// gather statistics ImageStatistics stat = new ImageStatistics( image ); // get red channel's histogram Histogram red = stat.Red; // check mean value of red channel if ( red.Mean > 128 ) { // do further processing }
예제 #1
0
        private double Runal(GaborFilter gaborFilter, Bitmap b)
        {
            try
            {
                Bitmap output = gaborFilter.Apply(b);

                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(output);
                var histogram = statistics.Gray;
                return(histogram.Mean);
            }
            catch (Exception e) { return(0); }
            //    featuredata = featuredata + mean + ",";
        }
예제 #2
0
        private static void runonadverse()
        {
            List <double> means   = new List <double>();
            List <double> stddeva = new List <double>();

            string[] file = Directory.GetFiles(Form1.adverse);
            for (int i = 0; i < file.Length; i++)
            {
                if (i == 30)
                {
                    break;
                }
                string dupImagePath = file[i];
                Bitmap org0         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);
                Bitmap org1         = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Bitmap noiserem     = org1;
                foreach (string filterid in ChromosomeDecode.algorithm)
                {
                    if (filterid.Equals("01"))
                    {
                        // Console.WriteLine("AdaptiveSmoothing");
                        Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else if (filterid.Equals("11"))
                    {
                        //  Console.WriteLine("AdditiveNoise");
                        Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else if (filterid.Equals("10"))
                    {
                        // Console.WriteLine("BilateralSmoothing");
                        Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else
                    {
                        ///donothing
                    }
                }
                Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);
                // apply the filter
                Bitmap resultImage = filter.Apply(noiserem);
                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);

                double mean   = 0.0; // histogram.Mean;     // mean red value
                double stddev = 0.0; // histogram.StdDev
                if (MainGA.genelength == 2)
                {
                    var histogram = statistics.Red;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                else
                {
                    var histogram = statistics.Gray;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                means.Add(mean);
                stddeva.Add(stddev);
                org0.Dispose();
                org1.Dispose();
                noiserem.Dispose();
                resultImage.Dispose();
            }

            adversupperrange  = stddeva.Average() + means.Average();
            adverselowerrange = Math.Abs(means.Average() - stddeva.Average());
        }
예제 #3
0
        public void bulkknoiseprocessmnist()
        {
            //string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\New folder (4)\a", "*.png");
            //   string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\GAN\tensorflow-adversarial-master\tensorflow-adversarial-master\example\img\fgsm", "*.png");
            //  string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\GAN\tensorflow-adversarial-master\tensorflow-adversarial-master\example\img\jsma\New folder", "*.png");

            //   string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\GAN\tensorflow-adversarial-master\tensorflow-adversarial-master\example\img\deepfool", "*.png");
            string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\GAN\tensorflow-adversarial-master\tensorflow-adversarial-master\example\img\cw2", "*.png");


            // string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\DS160\GAN\tensorflow-adversarial-master\tensorflow-adversarial-master\example\img\ADV GAN", "*.png");
            // System.Console.Write("\n" + descriptors.Count+"  v ");
            for (int i = 0; i < file.Length; i++)
            {
                if (i == 34)
                {
                    break;
                }
                string dupImagePath = file[i];
                Bitmap org1         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);
                Bitmap org2         = org1.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); // 1,2,3
                org1.Dispose();
                org1 = ToGrayscale(org2);
                //    Bitmap org2 = org1.Clone(System.Drawing.Imaging.PixelFormat.Format8bppIndexed); // 4
                //   Accord.Imaging.Filters.GrayscaleBT709 Grayscalea = new Accord.Imaging.Filters.GrayscaleBT709();//4
                //     org1=Grayscalea.Apply(org2);
                //   Accord.Imaging.Filters.AdaptiveSmoothing adaptiveSmoothing = new Accord.Imaging.Filters.AdaptiveSmoothing(); //1
                // Accord.Imaging.Filters.AdditiveNoise adaptiveSmoothing = new Accord.Imaging.Filters.AdditiveNoise(); //2
                //  Accord.Imaging.Filters.BilateralSmoothing adaptiveSmoothing = new Accord.Imaging.Filters.BilateralSmoothing();/3
                Accord.Imaging.Filters.ZhangSuenSkeletonization adaptiveSmoothing = new Accord.Imaging.Filters.ZhangSuenSkeletonization();//4



                Bitmap noiserem  = adaptiveSmoothing.Apply(org1);
                Bitmap noiserem1 = adaptiveSmoothing.Apply(noiserem);
                Bitmap noiserem2 = adaptiveSmoothing.Apply(noiserem1);
                Bitmap noiserem3 = adaptiveSmoothing.Apply(noiserem2);
                Bitmap noiserem4 = adaptiveSmoothing.Apply(noiserem3);
                Bitmap noiserem5 = adaptiveSmoothing.Apply(noiserem4);
                Bitmap noiserem6 = adaptiveSmoothing.Apply(noiserem5);
                Bitmap noiserem7 = adaptiveSmoothing.Apply(noiserem6);
                Bitmap noiserem8 = adaptiveSmoothing.Apply(noiserem7);
                Bitmap noiserem9 = adaptiveSmoothing.Apply(noiserem8);
                Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);



                // apply the filter
                Bitmap resultImage = filter.Apply(noiserem9);
                //  resultImage.Save(i + ".png");
                // HistogramsOfOrientedGradients hog = new HistogramsOfOrientedGradients(numberOfBins: 9, blockSize: 3, cellSize: 6);

                // Use it to extract descriptors from the Lena image:
                // List<double[]> descriptors = hog.ProcessImage(resultImage);
                //  var a = hog.Histograms;
                Accord.Imaging.ImageStatistics statistics =
                    new Accord.Imaging.ImageStatistics(resultImage);
                // get the red histogram
                var histogram = statistics.Gray;
                // get the values
                double mean   = histogram.Mean;   // mean red value
                double stddev = histogram.StdDev; // standard deviation of red values
                                                  //  int median = histogram.Median; // median red value
                                                  //  int min = histogram.Min;       // min red value
                                                  //   int max = histogram.Max;       // max value
                                                  // get 90% range around the median
                                                  //  var range = histogram.GetRange(0.9);

                Console.WriteLine("" + mean + "," + stddev);

                org2.Dispose();
                noiserem.Dispose();
                resultImage.Dispose();
            }
        }
예제 #4
0
        string mnist_adv      = @"C:\Users\kishor\Desktop\icsw\test\mnist\advgan"; //5

        //filters
        public void mnistbulkknoiseprocess(string filepath, int filterid, int times)
        {
            string[] file = Directory.GetFiles(filepath);
            for (int i = 0; i < file.Length; i++)
            {
                if (i == 30)
                {
                    break;
                }

                string dupImagePath = file[i];
                Bitmap org0         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);
                Bitmap org1         = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Bitmap noiserem     = null;
                save(i, org0, times + "_" + filterid + "_org0.png");
                save(i, org1, times + "_" + filterid + "_org1.png");
                if (filterid == 1)
                {
                    // Console.WriteLine("AdaptiveSmoothing");
                    Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 2)
                {
                    //  Console.WriteLine("AdditiveNoise");
                    Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 3)
                {
                    // Console.WriteLine("BilateralSmoothing");
                    Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 4)
                {
                    //  Console.WriteLine("SimpleSkeletonization");
                    Bitmap org2 = org1.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); // 1,2,3
                    org1.Dispose();
                    org1 = ToGrayscale(org2);
                    Accord.Imaging.Filters.ZhangSuenSkeletonization noisefilter = new Accord.Imaging.Filters.ZhangSuenSkeletonization();

                    Bitmap noiserem0 = noisefilter.Apply(org1);
                    Bitmap noiserem1 = noisefilter.Apply(noiserem0);
                    Bitmap noiserem2 = noisefilter.Apply(noiserem1);
                    Bitmap noiserem3 = noisefilter.Apply(noiserem2);
                    Bitmap noiserem4 = noisefilter.Apply(noiserem3);
                    save(i, noiserem4, times + "_" + filterid + "_noiserem4.png");
                    Bitmap noiserem5 = noisefilter.Apply(noiserem4);
                    Bitmap noiserem6 = noisefilter.Apply(noiserem5);
                    Bitmap noiserem7 = noisefilter.Apply(noiserem6);
                    Bitmap noiserem8 = noisefilter.Apply(noiserem7);
                    noiserem = noisefilter.Apply(noiserem8);
                }

                save(i, noiserem, times + "_" + filterid + "_noiserem.png");
                Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);



                // apply the filter
                Bitmap resultImage = filter.Apply(noiserem);

                save(i, resultImage, times + "_" + filterid + "_resultImage.png");
                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);
                // get the red histogram
                double mean   = 0.0; // histogram.Mean;     // mean red value
                double stddev = 0.0; // histogram.StdDev
                if (filterid != 4)
                {
                    var histogram = statistics.Red;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                else
                {
                    var histogram = statistics.Gray;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                // get the values
                // standard deviation of red values
                //  int median = histogram.Median; // median red value
                //  int min = histogram.Min;       // min red value
                //   int max = histogram.Max;       // max value
                // get 90% range around the median
                //  var range = histogram.GetRange(0.9);

                Console.WriteLine("" + mean + "," + stddev);



                org0.Dispose();
                org1.Dispose();
                noiserem.Dispose();
                resultImage.Dispose();
            }
        }
예제 #5
0
        /// <summary>
        /// ///////////////////////////
        /// cfiar
        /// </summary>
        public void Cfiarbulkknoiseprocess(string filepath, int filterid, int times)
        {
            string[] file = Directory.GetFiles(filepath);
            for (int i = 0; i < file.Length; i++)
            {
                if (i == 32)
                {
                    break;
                }
                string dupImagePath = file[i];
                Bitmap org1         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);
                Bitmap org2         = org1.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); // 1,2,3
                org1.Dispose();
                org1 = ToGrayscale(org2);
                Bitmap noiserem = null;

                if (filterid == 1)
                {
                    Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 2)
                {
                    Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 3)
                {
                    Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing();
                    noiserem = noisefilter.Apply(org1);
                }
                else if (filterid == 4)
                {
                    Accord.Imaging.Filters.SimpleSkeletonization noisefilter = new Accord.Imaging.Filters.SimpleSkeletonization();
                    noiserem = noisefilter.Apply(org1);
                }


                Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);



                // apply the filter
                Bitmap resultImage = filter.Apply(noiserem);
                //  resultImage.Save(i + ".png");

                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);
                // get the red histogram
                var histogram = statistics.Gray;
                // get the values
                double mean   = histogram.Mean;   // mean red value
                double stddev = histogram.StdDev; // standard deviation of red values
                                                  //  int median = histogram.Median; // median red value
                                                  //  int min = histogram.Min;       // min red value
                                                  //   int max = histogram.Max;       // max value
                                                  // get 90% range around the median
                                                  //  var range = histogram.GetRange(0.9);

                Console.WriteLine("" + mean + "," + stddev);
                rt.Text = rt.Text + "\n" + "" + mean + "," + stddev;
                org2.Dispose();
                noiserem.Dispose();
                resultImage.Dispose();
            }
        }
예제 #6
0
        public void MeasureContrast(IProgress <ApplicationStatus> progress)
        {
            try {
                using (MyStopWatch.Measure()) {
                    Stopwatch overall = Stopwatch.StartNew();
                    progress?.Report(new ApplicationStatus()
                    {
                        Status = "Preparing image for contrast measurement"
                    });

                    _bitmapToAnalyze = ImageUtility.Convert16BppTo8Bpp(_originalBitmapSource);

                    _token.ThrowIfCancellationRequested();

                    //Crop if there is ROI

                    if (UseROI && InnerCropRatio < 1)
                    {
                        Rectangle cropRectangle = GetCropRectangle(InnerCropRatio);
                        _bitmapToAnalyze = new Crop(cropRectangle).Apply(_bitmapToAnalyze);
                    }

                    if (_noiseReduction == NoiseReductionEnum.Median)
                    {
                        new Median().ApplyInPlace(_bitmapToAnalyze);
                    }

                    //Make sure resizing is independent of Star Sensitivity
                    _resizefactor        = (double)_maxWidth / _bitmapToAnalyze.Width;
                    _inverseResizefactor = 1.0 / _resizefactor;

                    /* Resize to speed up manipulation */
                    ResizeBitmapToAnalyze();

                    progress?.Report(new ApplicationStatus()
                    {
                        Status = "Measuring Contrast"
                    });

                    _token.ThrowIfCancellationRequested();

                    if (ContrastDetectionMethod == ContrastDetectionMethodEnum.Laplace)
                    {
                        if (_noiseReduction == NoiseReductionEnum.None || _noiseReduction == NoiseReductionEnum.Median)
                        {
                            int[,] kernel = new int[7, 7];
                            kernel        = LaplacianOfGaussianKernel(7, 1.0);
                            new Convolution(kernel).ApplyInPlace(_bitmapToAnalyze);
                        }
                        else if (_noiseReduction == NoiseReductionEnum.Normal)
                        {
                            int[,] kernel = new int[9, 9];
                            kernel        = LaplacianOfGaussianKernel(9, 1.4);
                            new Convolution(kernel).ApplyInPlace(_bitmapToAnalyze);
                        }
                        else if (_noiseReduction == NoiseReductionEnum.High)
                        {
                            int[,] kernel = new int[11, 11];
                            kernel        = LaplacianOfGaussianKernel(11, 1.8);
                            new Convolution(kernel).ApplyInPlace(_bitmapToAnalyze);
                        }
                        else
                        {
                            int[,] kernel = new int[13, 13];
                            kernel        = LaplacianOfGaussianKernel(13, 2.2);
                            new Convolution(kernel).ApplyInPlace(_bitmapToAnalyze);
                        }
                        //Get mean and standard dev
                        Accord.Imaging.ImageStatistics stats = new Accord.Imaging.ImageStatistics(_bitmapToAnalyze);
                        AverageContrast = stats.GrayWithoutBlack.Mean;
                        ContrastStdev   = 0.01; //Stdev of convoluted image is not a measure of error - using same figure for all
                    }
                    else if (ContrastDetectionMethod == ContrastDetectionMethodEnum.Sobel)
                    {
                        if (_noiseReduction == NoiseReductionEnum.None || _noiseReduction == NoiseReductionEnum.Median)
                        {
                            //Nothing to do
                        }
                        else if (_noiseReduction == NoiseReductionEnum.Normal)
                        {
                            _bitmapToAnalyze = new FastGaussianBlur(_bitmapToAnalyze).Process(1);
                        }
                        else if (_noiseReduction == NoiseReductionEnum.High)
                        {
                            _bitmapToAnalyze = new FastGaussianBlur(_bitmapToAnalyze).Process(2);
                        }
                        else
                        {
                            _bitmapToAnalyze = new FastGaussianBlur(_bitmapToAnalyze).Process(3);
                        }
                        int[,] kernel =
                        {
                            { -1, -2, 0,  2,  1 },
                            { -2, -4, 0,  4,  2 },
                            {  0,  0, 0,  0,  0 },
                            {  2,  4, 0, -4, -2 },
                            {  1,  2, 0, -2, -1 }
                        };
                        new Convolution(kernel).ApplyInPlace(_bitmapToAnalyze);
                        //Get mean and standard dev
                        Accord.Imaging.ImageStatistics stats = new Accord.Imaging.ImageStatistics(_bitmapToAnalyze);
                        AverageContrast = stats.GrayWithoutBlack.Mean;
                        ContrastStdev   = 0.01; //Stdev of convoluted image is not a measure of error - using same figure for all
                    }

                    _token.ThrowIfCancellationRequested();

                    _bitmapToAnalyze.Dispose();
                    overall.Stop();
                    Debug.Print("Overall contrast detection: " + overall.Elapsed);
                    overall = null;
                }
            } catch (OperationCanceledException) {
            } finally {
                progress?.Report(new ApplicationStatus()
                {
                    Status = string.Empty
                });
            }
            return;
        }
예제 #7
0
        private void runonadverse()
        {
            List <double> means   = new List <double>();
            List <double> stddeva = new List <double>();

            count = 0;
            string[] file = Directory.GetFiles(Form1.adverse);
            for (int i = 0; i < file.Length; i++)
            {
                if (i == imagetotal)
                {
                    break;
                }
                string dupImagePath = file[i];
                Bitmap org0         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);
                Bitmap org1         = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Bitmap noiserem     = org1;
                foreach (string filterid in algorithm)
                {
                    if (filterid.Equals("01"))
                    {
                        // Console.WriteLine("AdaptiveSmoothing");
                        Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else if (filterid.Equals("11"))
                    {
                        //  Console.WriteLine("AdditiveNoise");
                        Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else if (filterid.Equals("10"))
                    {
                        // Console.WriteLine("BilateralSmoothing");
                        Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing();
                        noiserem = noisefilter.Apply(noiserem);
                    }
                    else
                    {
                        ///donothing
                    }
                }
                Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);
                // apply the filter
                Bitmap resultImage = filter.Apply(noiserem);
                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);

                double mean   = 0.0; // histogram.Mean;     // mean red value
                double stddev = 0.0; // histogram.StdDev
                if (MainGA.genelength == 2)
                {
                    var histogram = statistics.Red;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                else
                {
                    var histogram = statistics.Gray;
                    mean   = histogram.Mean;   // mean red value
                    stddev = histogram.StdDev;
                }
                means.Add(mean);
                //  stddeva.Add(stddev);
                // org0.Dispose();
                //  org1.Dispose();
                //  noiserem.Dispose();
                //  resultImage.Dispose();

                if (!theadon)
                {
                    if (cleanupperrange > mean && cleanlowerrange > mean)
                    {
                        count++;
                    }
                    else if (mean > cleanupperrange && mean > cleanupperrange)
                    {
                        count++;
                    }
                    Console.WriteLine("count " + count + " index " + i);
                }


                //Form1.textlist.Add("count " + count + " index " + i);
            }

            adversupperrange  = StandardDeviation(means, 0, means.Count()) + means.Average();
            adverselowerrange = Math.Abs(means.Average() - StandardDeviation(means, 0, means.Count()));
            //  Form1.textlist.Add("adversupperrange " + adversupperrange + "adverselowerrange " + adverselowerrange);
            //     Console.WriteLine("adversupperrange " + adversupperrange + "adverselowerrange " + adverselowerrange);
        }
예제 #8
0
        public rettype runalgo(string s)
        {
            string dupImagePath = s;
            Bitmap org0         = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath);

            // Bitmap org1 = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            if (greyscaleenable)
            {
                Accord.Imaging.Filters.GrayscaleBT709 gr = new Accord.Imaging.Filters.GrayscaleBT709();
                org0 = gr.Apply(org0);
            }
            Bitmap org1 = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1);
            Bitmap noiserem = org1.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            foreach (string filterid in algorithm)
            {
                int filterno = getfilter(filterid);
                if (filterno == 2)
                {
                    // Console.WriteLine("AdaptiveSmoothing");
                    Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else if (filterno == 4)
                {
                    //  Console.WriteLine("AdditiveNoise");
                    Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else if (filterno == 3)
                {
                    //  Console.WriteLine("BilateralSmoothing");
                    Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing();
                    noiserem = noisefilter.Apply(noiserem);
                }
                if (filterno == 5)
                {
                    //Bitmap gra = new Bitmap(noiserem.Width, noiserem.Height, PixelFormat.Format8bppIndexed);

                    // Bitmap gra = new bnoiserem.Clone(System.Drawing.Imaging.PixelFormat.form);
                    // Console.WriteLine("AdaptiveSmoothing");
                    Accord.Imaging.Filters.Erosion noisefilter = new Accord.Imaging.Filters.Erosion();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else if (filterno == 6)
                {
                    //  Console.WriteLine("AdditiveNoise");
                    Accord.Imaging.Filters.Pixellate noisefilter = new Accord.Imaging.Filters.Pixellate();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else if (filterno == 7)
                {
                    //  Console.WriteLine("BilateralSmoothing");
                    Accord.Imaging.Filters.GaussianBlur noisefilter = new Accord.Imaging.Filters.GaussianBlur();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else if (filterno == 8)
                {
                    //  Console.WriteLine("BilateralSmoothing");
                    Accord.Imaging.Filters.GaussianSharpen noisefilter = new Accord.Imaging.Filters.GaussianSharpen();
                    noiserem = noisefilter.Apply(noiserem);
                }
                else
                {
                    ///donothing
                }
            }

            // apply the filter

            Bitmap resultImage = filter.Apply(noiserem);


            double mean = 0.0;// histogram.Mean;     // mean red value

            Accord.Statistics.Visualizations.Histogram histogram = null;;
            if (greyscaleenable == false)
            {
                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);
                histogram = statistics.Red;
                mean      = histogram.Mean; // mean red value
            }
            else
            {
                Accord.Imaging.Filters.GrayscaleBT709 gr = new Accord.Imaging.Filters.GrayscaleBT709();
                resultImage = gr.Apply(resultImage);
                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage);

                histogram = statistics.Gray;
                mean      = histogram.Mean; // mean red value
            }
            var lbp = new LocalBinaryPattern(blockSize: 3, cellSize: 6);

            // Use it to extract descriptors from the Lena image:
            var    descriptors = lbp.ProcessImage(resultImage);
            double av          = 0.0;

            foreach (var d in descriptors)
            {
                av = av + d.Average();
            }
            av = av / descriptors.Count;



            rettype ret = new rettype();

            ret.histogram = histogram;
            ret.lbpavg    = av;
            ret.histoavg  = mean;

            return(ret);
        }
        private double census(Bitmap myBitmap)
        {
            int[,] bi = new int[myBitmap.Width, myBitmap.Height];

            for (int x = 0; x < myBitmap.Width; x++)
            {
                for (int y = 0; y < myBitmap.Height; y++)
                {
                    Color pixelColor = myBitmap.GetPixel(x, y);
                    int   mainvalue  = pixelColor.R;

                    string s = "";
                    try
                    {
                        int a0 = myBitmap.GetPixel(x - 1, y - 1).R;
                        if (a0 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }

                    try
                    {
                        int a1 = myBitmap.GetPixel(x - 1, y).R;
                        if (a1 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a2 = myBitmap.GetPixel(x - 1, y + 1).R;
                        if (a2 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a3 = myBitmap.GetPixel(x, y - 1).R;
                        if (a3 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a4 = myBitmap.GetPixel(x, y + 1).R;
                        if (a4 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a6 = myBitmap.GetPixel(x + 1, y + 1).R;
                        if (a6 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a7 = myBitmap.GetPixel(x + 1, y).R;
                        if (a7 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }
                    try
                    {
                        int a8 = myBitmap.GetPixel(x + 1, y - 1).R;
                        if (a8 >= mainvalue)
                        {
                            s = s + 1;
                        }
                        else
                        {
                            s = s + 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        s = s + "";
                    }

                    bi[x, y] = BitStringToInt(s);


                    //      neighbors(1) = img(r - 1, c - 1); % Upper left.r = row, c = column.
                    // neighbors(2) = img(r - 1, c); % Upper middle.r = row, c = column.
                    //  neighbors(3) = img(r - 1, c + 1); % Upper right.r = row, c = column.
                    //   neighbors(4) = img(r, c - 1); % left.r = row, c = column.
                    //    neighbors(5) = img(r, c + 1); % right.r = row, c = column.

                    //    neighbors(6) = img(r + 1, c + 1); % Lowerleft.r = row, c = column.
                    //   neighbors(7) = img(r + 1, c); % lower middle.r = row, c = column.
                    //  neighbors(8) = img(r + 1, c - 1); % Lower left.r = row, c = column.

                    // things we do with pixelColor
                }
            }

            MatrixToImage conv = new MatrixToImage(min: 0, max: 255);

            // Declare an image and store the pixels on it
            Bitmap image; conv.Convert(bi, out image);

            Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(image);
            var histogram = statistics.Gray;

            return(histogram.Mean);
        }