Пример #1
0
        static public Image Vylf(ObjectAPI picture, double k, int a, ref Stopwatch st2)
        {
            ObjectAPI pic  = picture.Clone() as ObjectAPI;
            ObjectAPI pic2 = picture.Clone() as ObjectAPI;
            double    R    = 0;

            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    var r = ConvertMatrixVylf2(pic, a, i, j);
                    if (R < r)
                    {
                        R = r;
                    }
                }
            }
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    var t = ConvertMatrixVylf(pic, a, i, j, k, pic.MinPix, R);
                    if (pic.Rmatrix[j, i] <= t)
                    {
                        pic2.Rmatrix[j, i] = 0;
                    }
                    if (pic.Rmatrix[j, i] > t)
                    {
                        pic2.Rmatrix[j, i] = 255;
                    }
                }
            }
            st2.Stop();
            return(pic2.Show());
        }
Пример #2
0
        static public Image Niblek(ObjectAPI picture, double k, int a, ref Stopwatch st2)
        {
            ObjectAPI pic = new ObjectAPI();

            pic = picture.Clone() as ObjectAPI;
            ObjectAPI pic2 = new ObjectAPI();

            pic2 = picture.Clone() as ObjectAPI;
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    var t = ConvertMatrixNiblek(pic, a, i, j, k);
                    if (pic.Rmatrix[j, i] <= t)
                    {
                        pic2.Rmatrix[j, i] = 0;
                    }
                    if (pic.Rmatrix[j, i] > t)
                    {
                        pic2.Rmatrix[j, i] = 255;
                    }
                }
            }
            st2.Stop();
            return(pic2.Show());
        }
Пример #3
0
        static public double ConvertMatrixNiblek(ObjectAPI pic, int a, int ii, int jj, double k)
        {
            int x1 = jj - a;
            int x2 = jj + a;
            int y1 = ii - a;
            int y2 = ii + a;
            int S1 = 0;
            int S2 = 0;
            int S3 = 0;
            int S4 = 0;

            if (x1 <= 0)
            {
                x1 = 1;
            }
            if (x2 >= pic.Width)
            {
                x2 = pic.Width - 1;
            }
            if (y1 <= 0)
            {
                y1 = 1;
            }
            if (y2 >= pic.Height)
            {
                y2 = pic.Height - 1;
            }
            S4 = pic.RmatrixSum[x2, y1 - 1];
            S3 = pic.RmatrixSum[x1 - 1, y2];
            S2 = pic.RmatrixSum[x1 - 1, y1 - 1];
            S1 = pic.RmatrixSum[x2, y2];

            int SS1 = 0;
            int SS2 = 0;
            int SS3 = 0;
            int SS4 = 0;

            SS1 = pic.RmatrixMulti[x2, y2];

            SS2 = pic.RmatrixMulti[x1 - 1, y1 - 1];

            SS3 = pic.RmatrixMulti[x1 - 1, y2];

            SS4 = pic.RmatrixMulti[x2, y1 - 1];

            var Mx  = S1 + S2 - S3 - S4;
            var Mx2 = SS1 + SS2 - SS3 - SS4;

            int Size = (int)Math.Pow((2 * a) + 1, 2);

            Mx  /= Size;
            Mx2 /= Size;
            double D     = Mx2 - (Mx * Mx);
            var    sigma = Math.Sqrt(D);
            var    t     = Mx + (k * sigma);

            return(t);
        }
      public static Bitmap MaxPix(List <ObjectAPI> pictures)
      {
          var result = new Bitmap(758, 695);

          ObjectAPI[] mass = new ObjectAPI[pictures.Count()];
          for (int i = 0; i < pictures.Count(); i++)
          {
              mass[i] = pictures[i].Clone() as ObjectAPI;
          }
          int w         = mass[0].Width;
          int h         = mass[0].Height;
          var ImgResult = new Bitmap(w, h);

          for (int k = mass.Count() - 1; k > 0; k--)
          {
              for (int i = 0; i < FindHeight(pictures); i++)
              {
                  for (int j = 0; j < FindWidth(pictures); j++)
                  {
                      if (mass[k - 1].matrix[j, i].R > mass[k].matrix[j, i].R)
                      {
                          mass[k - 1].matrix[j, i].R = mass[k].matrix[j, i].R;
                      }

                      if (mass[k - 1].matrix[j, i].G > mass[k].matrix[j, i].G)
                      {
                          mass[k - 1].matrix[j, i].G = mass[k].matrix[j, i].G;
                      }

                      if (mass[k - 1].matrix[j, i].B > mass[k].matrix[j, i].B)
                      {
                          mass[k - 1].matrix[j, i].B = mass[k].matrix[j, i].B;
                      }
                  }
              }
          }
          for (int i = 0; i < mass[0].Height; i++)
          {
              for (int j = 0; j < mass[0].Width; j++)
              {
                  Color pix = Color.FromArgb((int)mass[0].matrix[j, i].R, (int)mass[0].matrix[j, i].G, (int)mass[0].matrix[j, i].B);
                  ImgResult.SetPixel(j, i, pix);
              }
          }
          //throw new Exception();
          var g = Graphics.FromImage(result);

          g.DrawImage(ImgResult, 0, 0, 758, 695);
          g.Dispose();
          ImgResult.Dispose();
          return(result);
      }
Пример #5
0
        private void MainChart_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button.HasFlag(MouseButtons.Left))
            {
                ChartArea     ca = MainChart.ChartAreas[0];
                Axis          ax = ca.AxisX;
                Axis          ay = ca.AxisY;
                int           X = e.X, Y = e.Y;
                HitTestResult hit = MainChart.HitTest(e.X, e.Y);
                if (hit.PointIndex > 0)
                {
                    curPoint = hit.Series.Points[hit.PointIndex];
                }

                //if (curPoint != null)
                //{
                //    if (curPoint.XValue == 255 && curPoint.YValues[0] == 255) curPoint = null;
                //    if (curPoint.XValue == 0 && curPoint.YValues[0] == 0) curPoint = null;
                //    if (MainChart.Series[0].Points[MainChart.Series[0].Points.Count() - 1] == curPoint) curPoint = null;
                //    if (MainChart.Series[0].Points[0] == curPoint) curPoint = null;

                //}
                if (curPoint != null)
                {
                    Series s  = hit.Series;
                    double dx = ax.PixelPositionToValue(e.X);
                    double dy = ay.PixelPositionToValue(e.Y);

                    curPoint.XValue     = dx;
                    curPoint.YValues[0] = dy;
                }


                ObjectAPI pic2 = pic.Clone() as ObjectAPI;
                //pic2.ChangeGist(MainChart,str);
                Gist.Series[str2].Points.Clear();

                if (flag == false)
                {
                    Parallel.Invoke(() => Gist = Curve.loadGist(Gist, pic2, str2), () => pic2.ChangeGist(MainChart, str), () => MainPic.Image = pic2.ShowRGB());
                }
                //MainPic.Image = pic2.ShowRGB();
                else
                {
                    Parallel.Invoke(() => Gist = Curve.loadGist(Gist, pic2, str2), () => pic2.ChangeGist(MainChart, str), () => MainPic.Image = pic2.Show());
                }
                //MainPic.Image = pic2.Show();
                MainPic.Refresh();
                Gist = Curve.loadGist(Gist, pic2, str2);
            }
        }
Пример #6
0
        static public Image Otcu(ObjectAPI picture, ref Stopwatch st2)
        {
            ObjectAPI pic = new ObjectAPI();

            pic = picture.Clone() as ObjectAPI;
            var w = pic.Width;
            var h = pic.Height;

            double[] I = new double[256];
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    ++I[pic.Rmatrix[j, i]];
                }
            }
            for (int i = 0; i < I.Count(); i++)
            {
                I[i] = I[i] / (w * h);
            }
            double deltaDef = 0;
            int    tDef     = 0;

            for (int t = 0; t < pic.MaxPix; t++)
            {
                CalcOtcu(I, t, pic.MaxPix, ref deltaDef, ref tDef);
            }
            //throw new Exception();
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    if (pic.Rmatrix[j, i] <= tDef)
                    {
                        pic.Rmatrix[j, i] = 0;
                    }
                    if (pic.Rmatrix[j, i] > tDef)
                    {
                        pic.Rmatrix[j, i] = 255;
                    }
                }
            }
            st2.Stop();
            return(pic.Show());
        }
Пример #7
0
        public object Clone()
        {
            ObjectAPI aPI = new ObjectAPI();

            aPI.Height       = Height;
            aPI.Width        = Width;
            aPI.FileName     = FileName;
            aPI.MaxPix       = MaxPix;
            aPI.MinPix       = MinPix;
            aPI.matrix       = matrix.Clone() as RGB_Double[, ];
            aPI.Rmatrix      = Rmatrix.Clone() as byte[, ];
            aPI.RmatrixSum   = RmatrixSum.Clone() as int[, ];
            aPI.RmatrixMulti = RmatrixMulti.Clone() as int[, ];
            aPI.GistI        = GistI.Clone() as int[];
            aPI.GistRGB.R    = GistRGB.R.Clone() as int[];
            aPI.GistRGB.G    = GistRGB.G.Clone() as int[];
            aPI.GistRGB.B    = GistRGB.B.Clone() as int[];
            return(aPI);
        }
Пример #8
0
        static public Image LinFilter(ObjectAPI pic, int a, double[,] filterMatrix, ref Stopwatch st)
        {
            ObjectAPI pic2 = new ObjectAPI();

            pic2 = pic.Clone() as ObjectAPI;
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    int[,] R            = FilterArray(CreateMatrix(pic, a, i, j, 'R'), a);
                    int[,] G            = FilterArray(CreateMatrix(pic, a, i, j, 'G'), a);
                    int[,] B            = FilterArray(CreateMatrix(pic, a, i, j, 'B'), a);
                    pic2.matrix[j, i].R = GetReadyLinFilter(R, filterMatrix, a);
                    pic2.matrix[j, i].G = GetReadyLinFilter(G, filterMatrix, a);
                    pic2.matrix[j, i].B = GetReadyLinFilter(B, filterMatrix, a);
                }
            }

            st.Stop();
            return(pic2.ShowRGB());
        }
Пример #9
0
        static public Image MedianaFilter(ObjectAPI pic, int a, ref Stopwatch st)
        {
            ObjectAPI pic2 = new ObjectAPI();

            pic2 = pic.Clone() as ObjectAPI;
            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    byte[] R = FilterMedianaArray(CreateMatrix(pic, a, i, j, 'R'), a);
                    byte[] G = FilterMedianaArray(CreateMatrix(pic, a, i, j, 'G'), a);
                    byte[] B = FilterMedianaArray(CreateMatrix(pic, a, i, j, 'B'), a);
                    pic2.matrix[j, i].R = Math_Methods.QuickSelect_median(R);
                    pic2.matrix[j, i].G = Math_Methods.QuickSelect_median(G);
                    pic2.matrix[j, i].B = Math_Methods.QuickSelect_median(B);
                }
            }

            st.Stop();
            return(pic2.ShowRGB());
        }
Пример #10
0
        static public double[] ConvertMatrixBredly(ObjectAPI pic, int a, int ii, int jj)
        {
            int Size = (int)Math.Pow((2 * a) + 1, 2);
            int S1   = 0;
            int S2   = 0;
            int S3   = 0;
            int S4   = 0;
            int x1   = jj - a;
            int x2   = jj + a;
            int y1   = ii - a;
            int y2   = ii + a;

            if (x1 <= 0)
            {
                x1 = 1;
            }
            if (x2 >= pic.Width)
            {
                x2 = pic.Width - 1;
            }
            if (y1 <= 0)
            {
                y1 = 1;
            }
            if (y2 >= pic.Height)
            {
                y2 = pic.Height - 1;
            }
            S4 = pic.RmatrixSum[x2, y1 - 1];
            S3 = pic.RmatrixSum[x1 - 1, y2];
            S2 = pic.RmatrixSum[x1 - 1, y1 - 1];
            S1 = pic.RmatrixSum[x2, y2];
            var sum = S1 + S2 - S3 - S4;

            double[] result = new double[2];
            result[0] = sum;
            result[1] = Size;
            return(result);
        }
Пример #11
0
        private void MainChart_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button.HasFlag(MouseButtons.Right))
            {
                double    X  = Convert.ToDouble(Lx.Text);
                double    Y  = Convert.ToDouble(Ly.Text);
                DataPoint dp = new DataPoint(X, Y);

                dp.MarkerStyle = MarkerStyle.Square;
                dp.MarkerColor = Color.Red;

                var mass = MainChart.Series[str].Points.ToArray();
                for (int i = 0; i < mass.Count(); i++)
                {
                    if ((int)X == (int)mass[i].XValue)
                    {
                        return;
                    }
                }
                MainChart.Series[str].Points.Add(dp);
                MainChart.Series[str].Sort(PointSortOrder.Ascending);
                ObjectAPI pic2 = pic.Clone() as ObjectAPI;
                //pic2.ChangeGist(MainChart,str);
                Gist.Series[str2].Points.Clear();

                if (flag == false)
                {
                    Parallel.Invoke(() => Gist = Curve.loadGist(Gist, pic2, str2), () => pic2.ChangeGist(MainChart, str), () => MainPic.Image = pic2.ShowRGB());
                }
                //MainPic.Image = pic2.ShowRGB();
                else
                {
                    Parallel.Invoke(() => Gist = Curve.loadGist(Gist, pic2, str2), () => pic2.ChangeGist(MainChart, str), () => MainPic.Image = pic2.Show());
                }
                //MainPic.Image = pic2.Show();
                //Gist = Curve.loadGist(Gist, pic2, str2);
                MainPic.Refresh();
            }
        }
Пример #12
0
        static public Chart loadGist(Chart chart, ObjectAPI pic, string flag)
        {
            Chart chart1 = chart;

            if (flag == "GR")
            {
                int max = pic.GistRGB.R.Max();
                for (int i = 0; i < 256; i++)
                {
                    chart1.Series["GR"].Points.AddXY(i, pic.GistRGB.R[i]);
                }
            }
            if (flag == "GG")
            {
                int max = pic.GistRGB.G.Max();
                for (int i = 0; i < 256; i++)
                {
                    chart1.Series["GG"].Points.AddXY(i, pic.GistRGB.G[i]);
                }
            }
            if (flag == "GB")
            {
                int max = pic.GistRGB.B.Max();
                for (int i = 0; i < 256; i++)
                {
                    chart1.Series["GB"].Points.AddXY(i, pic.GistRGB.B[i]);
                }
            }
            if (flag == "GI")
            {
                int max = pic.GistI.Max();
                for (int i = 0; i < 256; i++)
                {
                    chart1.Series["GI"].Points.AddXY(i, pic.GistI[i]);
                }
            }

            return(chart1);
        }
Пример #13
0
        static public Image Bredly(ObjectAPI picture, double k, int a, ref Stopwatch st2)
        {
            ObjectAPI pic  = picture.Clone() as ObjectAPI;
            ObjectAPI pic2 = picture.Clone() as ObjectAPI;

            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    var t = ConvertMatrixBredly(pic, a, i, j);
                    if (pic.Rmatrix[j, i] * t[1] < t[0] * (1 - k))
                    {
                        pic2.Rmatrix[j, i] = 0;
                    }
                    if (pic.Rmatrix[j, i] * t[1] >= t[0] * (1 - k))
                    {
                        pic2.Rmatrix[j, i] = 255;
                    }
                }
            }
            st2.Stop();
            return(pic2.Show());
        }
Пример #14
0
        static public Image Gavr(ObjectAPI picture, ref Stopwatch st2)
        {
            ObjectAPI pic = new ObjectAPI();

            pic = picture.Clone() as ObjectAPI;
            double sum = 0;
            var    w   = pic.Width;
            var    h   = pic.Height;

            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    sum += pic.Rmatrix[j, i];
                }
            }
            var t = sum / (w * h);

            for (int i = 0; i < pic.Height; i++)
            {
                for (int j = 0; j < pic.Width; j++)
                {
                    if (pic.Rmatrix[j, i] <= t)
                    {
                        pic.Rmatrix[j, i] = 0;
                    }

                    if (pic.Rmatrix[j, i] > t)
                    {
                        pic.Rmatrix[j, i] = 255;
                    }
                }
            }
            st2.Stop();
            return(pic.Show());
        }
Пример #15
0
 static public int[,] CreateMatrix(ObjectAPI pic, int a, int ii, int jj, char flag)
 {
     //int Size = (int)Math.Pow((2 * a) + 1, 2);
     if (flag == 'R')
     {
         int[,] Matrix = new int[(2 * a) + 1, (2 * a) + 1];
         int iii = 0;
         for (int i = ii - a; i <= ii + a; i++)
         {
             int jjj = 0;
             for (int j = jj - a; j <= jj + a; j++)
             {
                 if ((j >= 0) && (i >= 0) && (j < pic.Width) && (i < pic.Height))
                 {
                     Matrix[iii, jjj] = (int)pic.matrix[j, i].R;
                 }
                 else
                 {
                     Matrix[iii, jjj] = -1;
                 }
                 jjj++;
             }
             iii++;
         }
         return(Matrix);
     }
     if (flag == 'G')
     {
         int[,] Matrix = new int[(2 * a) + 1, (2 * a) + 1];
         int iii = 0;
         for (int i = ii - a; i <= ii + a; i++)
         {
             int jjj = 0;
             for (int j = jj - a; j <= jj + a; j++)
             {
                 if ((j >= 0) && (i >= 0) && (j < pic.Width) && (i < pic.Height))
                 {
                     Matrix[iii, jjj] = (int)pic.matrix[j, i].G;
                 }
                 else
                 {
                     Matrix[iii, jjj] = -1;
                 }
                 jjj++;
             }
             iii++;
         }
         return(Matrix);
     }
     if (flag == 'B')
     {
         int[,] Matrix = new int[(2 * a) + 1, (2 * a) + 1];
         int iii = 0;
         for (int i = ii - a; i <= ii + a; i++)
         {
             int jjj = 0;
             for (int j = jj - a; j <= jj + a; j++)
             {
                 if ((j >= 0) && (i >= 0) && (j < pic.Width) && (i < pic.Height))
                 {
                     Matrix[iii, jjj] = (int)pic.matrix[j, i].B;
                 }
                 else
                 {
                     Matrix[iii, jjj] = -1;
                 }
                 jjj++;
             }
             iii++;
         }
         return(Matrix);
     }
     return(null);
 }