Exemple #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());
        }
Exemple #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());
        }
Exemple #3
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());
        }
Exemple #4
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());
        }
        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());
        }
        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());
        }
Exemple #7
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());
        }