Exemple #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));
     }
 }
Exemple #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);
     }
 }
Exemple #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)));
     }
 }
Exemple #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);
                }
            }
        }
Exemple #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);
     }
 }
Exemple #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);
        }
Exemple #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]);
                }
            }
        }
Exemple #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]);
                }
            }
        }
Exemple #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]);
                }
            }
        }
Exemple #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);
                }
            }
        }
Exemple #11
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]);
     }
 }
Exemple #12
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]);
     }
 }
Exemple #13
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]);
     }
 }
Exemple #14
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)));
 }
Exemple #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;
 }
Exemple #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);
 }