예제 #1
0
 public static void fill_random(Floatarray v, float lo, float hi)
 {
     for (int i = 0; i < v.Length1d(); i++)
     {
         v.Put1d(i, (float)((hi - lo) * DRandomizer.Default.drand() + lo));
     }
 }
예제 #2
0
 public static void binarize_with_threshold(Bytearray result, Floatarray image, float threshold)
 {
     result.MakeLike(image);
     for (int i = 0; i < image.Length1d(); i++)
     {
         result.Put1d(i, image.At1d(i) < threshold ? (byte)0 : (byte)255);
     }
 }
예제 #3
0
 /// <summary>
 /// Brushfire transformation using 2-norm.
 /// </summary>
 public static void brushfire_2(ref Floatarray distance, ref Narray <Point> source, float maxdist)
 {
     BrushFire.Go(Metric2.Default, ref distance, ref source, maxdist);
     for (int i = 0; i < distance.Length1d(); i++)
     {
         distance.Put1d(i, (float)Math.Sqrt(distance.At1d(i)));
     }
 }
예제 #4
0
        public static void Sparsify(Floatarray a, int n)
        {
            NBest nbest = new NBest(n);

            for (int i = 0; i < a.Length1d(); i++)
            {
                nbest.Add(i, Math.Abs(a.At1d(i)));
            }
            double threshold = nbest.Value(n - 1);

            for (int i = 0; i < a.Length1d(); i++)
            {
                if (Math.Abs(a.At1d(i)) < threshold)
                {
                    a.Put1d(i, 0f);
                }
            }
        }
예제 #5
0
 public static void binarize_by_range(Bytearray outa, Floatarray ina, float fraction)
 {
     float imin = NarrayUtil.Min(ina);
     float imax = NarrayUtil.Max(ina);
     float thresh = (int)(imin + (imax - imin) * fraction);
     outa.MakeLike(ina);
     for (int i = 0; i < ina.Length1d(); i++)
     {
         if (ina.At1d(i) > thresh) outa.Put1d(i, 255);
         else outa.Put1d(i, 0);
     }
 }
예제 #6
0
        protected static int count_zeros(Floatarray a)
        {
            int n     = a.Length1d();
            int count = 0;

            for (int i = 0; i < n; i++)
            {
                if (a.UnsafeAt1d(i) == 0f)
                {
                    count++;
                }
            }
            return(count);
        }
예제 #7
0
        public static void remove_dontcares(ref Intarray image)
        {
            Floatarray     dist   = new Floatarray();
            Narray <Point> source = new Narray <Point>();

            dist.Resize(image.Dim(0), image.Dim(1));
            for (int i = 0; i < dist.Length1d(); i++)
            {
                if (!dontcare(image.At1d(i)))
                {
                    dist.Put1d(i, (image.At1d(i) > 0 ? 1 : 0));
                }
            }
            BrushFire.brushfire_2(ref dist, ref source, 1000000);
            for (int i = 0; i < dist.Length1d(); i++)
            {
                Point p = source.At1d(i);
                if (dontcare(image.At1d(i)))
                {
                    image.Put1d(i, image[p.X, p.Y]);
                }
            }
        }
예제 #8
0
        public static void propagate_labels_to(ref Intarray target, Intarray seed)
        {
            Floatarray     dist   = new Floatarray();
            Narray <Point> source = new Narray <Point>();

            dist.Copy(seed);
            BrushFire.brushfire_2(ref dist, ref source, 1000000);
            for (int i = 0; i < dist.Length1d(); i++)
            {
                Point p = source.At1d(i);
                if (target.At1d(i) > 0)
                {
                    target.Put1d(i, seed[p.X, p.Y]);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Propagate labels across the entire image from a set of non-zero seeds.
        /// </summary>
        public static void propagate_labels(ref Intarray image)
        {
            Floatarray     dist   = new Floatarray();
            Narray <Point> source = new Narray <Point>();

            dist.Copy(image);
            BrushFire.brushfire_2(ref dist, ref source, 1000000);
            for (int i = 0; i < dist.Length1d(); i++)
            {
                Point p = source.At1d(i);
                if (image.At1d(i) == 0)
                {
                    image.Put1d(i, image[p.X, p.Y]);
                }
            }
        }
예제 #10
0
        public static void binarize_by_range(Bytearray outa, Floatarray ina, float fraction)
        {
            float imin   = NarrayUtil.Min(ina);
            float imax   = NarrayUtil.Max(ina);
            float thresh = (int)(imin + (imax - imin) * fraction);

            outa.MakeLike(ina);
            for (int i = 0; i < ina.Length1d(); i++)
            {
                if (ina.At1d(i) > thresh)
                {
                    outa.Put1d(i, 255);
                }
                else
                {
                    outa.Put1d(i, 0);
                }
            }
        }
예제 #11
0
파일: ImgLabels.cs 프로젝트: nickun/OCRonet
 public static void remove_dontcares(ref Intarray image)
 {
     Floatarray dist = new Floatarray();
     Narray<Point> source = new Narray<Point>();
     dist.Resize(image.Dim(0), image.Dim(1));
     for (int i = 0; i < dist.Length1d(); i++)
         if (!dontcare(image.At1d(i))) dist.Put1d(i, (image.At1d(i) > 0 ? 1 : 0));
     BrushFire.brushfire_2(ref dist, ref source, 1000000);
     for (int i = 0; i < dist.Length1d(); i++)
     {
         Point p = source.At1d(i);
         if (dontcare(image.At1d(i))) image.Put1d(i, image[p.X, p.Y]);
     }
 }
예제 #12
0
파일: ImgLabels.cs 프로젝트: nickun/OCRonet
 public static void propagate_labels_to(ref Intarray target, Intarray seed)
 {
     Floatarray dist = new Floatarray();
     Narray<Point> source = new Narray<Point>();
     dist.Copy(seed);
     BrushFire.brushfire_2(ref dist, ref source, 1000000);
     for (int i = 0; i < dist.Length1d(); i++)
     {
         Point p = source.At1d(i);
         if (target.At1d(i) > 0) target.Put1d(i, seed[p.X, p.Y]);
     }
 }
예제 #13
0
파일: ImgLabels.cs 프로젝트: nickun/OCRonet
 /// <summary>
 /// Propagate labels across the entire image from a set of non-zero seeds.
 /// </summary>
 public static void propagate_labels(ref Intarray image)
 {
     Floatarray dist = new Floatarray();
     Narray<Point> source = new Narray<Point>();
     dist.Copy(image);
     BrushFire.brushfire_2(ref dist, ref source, 1000000);
     for (int i = 0; i < dist.Length1d(); i++)
     {
         Point p = source.At1d(i);
         if (image.At1d(i) == 0) image.Put1d(i, image[p.X, p.Y]);
     }
 }
예제 #14
0
파일: BrushFire.cs 프로젝트: nickun/OCRonet
 /// <summary>
 /// Brushfire transformation using 2-norm.
 /// </summary>
 public static void brushfire_2(ref Floatarray distance, ref Narray<Point> source, float maxdist)
 {
     BrushFire.Go(Metric2.Default, ref distance, ref source, maxdist);
     for (int i = 0; i < distance.Length1d(); i++)
         distance.Put1d(i, (float)Math.Sqrt(distance.At1d(i)));
 }
예제 #15
0
 protected static int count_zeros(Floatarray a)
 {
     int n = a.Length1d();
     int count = 0;
     for (int i = 0; i < n; i++)
         if (a.UnsafeAt1d(i) == 0f) count++;
     return count;
 }
예제 #16
0
 public static void binarize_with_threshold(Bytearray result, Floatarray image, float threshold)
 {
     result.MakeLike(image);
     for (int i = 0; i < image.Length1d(); i++)
         result.Put1d(i, image.At1d(i) < threshold ? (byte)0 : (byte)255);
 }