Exemplo n.º 1
0
 void adversecheck(rettype d)
 {
     //Form1.textlist.Add("adv count  "+ adversecorrect.Count());
     if (cleanupperrange <= d.histoavg || d.histoavg <= cleanlowerrange)
     {
         adversecorrect.Add("1");
     }
     else
     {
         adversecorrect.Add("1");
     }
 }
Exemplo n.º 2
0
        void cleancheck(rettype d)
        {
            //  Form1.textlist.Add("clean count "+cleancorrect.Count()+"");

            if (cleanupperrange >= d.histoavg && d.histoavg >= cleanlowerrange)
            {
                cleancorrect.Add("1");
            }
            else
            {
                cleanincorrect.Add("1");
            }
        }
Exemplo n.º 3
0
        private void runonadverseonthread()
        {
            ObservableCollection <double> means    = new ObservableCollection <double>();
            ObservableCollection <double> lbpmeans = new ObservableCollection <double>();
            ObservableCollection <double> L        = new ObservableCollection <double>();

            Accord.Statistics.Visualizations.Histogram histogram = null;
            //List<double> stddeva = new List<double>();
            count = 0;

            string[] file = Directory.GetFiles(Form1.adverse);
            if (imagetotal > file.Length)
            {
                imagetotal = file.Length;
            }
            var T1 = Task.Run(() => {
                for (int i = 0; i < threadcount * 1; i++)
                {
                    //  Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T2 = Task.Run(() => {
                for (int i = threadcount * 1; i < threadcount * 2; i++)
                {
                    //  Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T3 = Task.Run(() => {
                for (int i = threadcount * 2; i < threadcount * 3; i++)
                {
                    // Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T4 = Task.Run(() => {
                for (int i = threadcount * 3; i <= threadcount * 4; i++)
                {
                    // Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T5 = Task.Run(() => {
                for (int i = threadcount * 4; i < threadcount * 5; i++)
                {
                    //  Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T6 = Task.Run(() => {
                for (int i = threadcount * 5; i < threadcount * 6; i++)
                {
                    // Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T7 = Task.Run(() => {
                for (int i = threadcount * 6; i < threadcount * 7; i++)
                {
                    // Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });
            var T8 = Task.Run(() => {
                for (int i = threadcount * 7; i < file.Length; i++)
                {
                    // Form1.textlist.Add("adverse count  " + i);
                    if (i >= imagetotal)
                    {
                        break;
                    }
                    rettype rt = runalgo(file[i]);
                    means.Add(rt.histoavg);
                    lbpmeans.Add(rt.lbpavg);
                    if (histogram == null)
                    {
                        histogram = rt.histogram;
                    }
                    else
                    {
                        histogram.Add(rt.histogram);
                    }
                    L.Add(CEL.Lcalculate(0, rt.histogram));
                }
            });

            T1.Wait();
            T2.Wait();
            T3.Wait();
            T4.Wait();
            T5.Wait();
            T6.Wait();
            T7.Wait();
            T8.Wait();
            // Form1.textlist.Add("total sample processed " + means.Count());
            double std = StandardDeviation(means.ToList(), 0, means.Count());
            double avg = means.Average();

            adversupperrange  = std + avg;
            adverselowerrange = Math.Abs(avg - std);

            std = StandardDeviation(lbpmeans.ToList(), 0, lbpmeans.Count());
            avg = means.Average();
            lbp_adversupperrange  = std + avg;
            lbp_adverselowerrange = Math.Abs(avg - std);
            //   Form1.textlist.Add(sta+" adversupperrange " + adversupperrange + " adverselowerrange " + adverselowerrange);
            adv_histogram = histogram;
            Ladvvalueavg  = L.Average();
            Lvaluesum     = Lvaluesum + L.Sum();
        }
Exemplo n.º 4
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);
        }