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)); } }
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); } }
/// <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))); } }
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); } } }
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); } }
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); }
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]); } } }
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]); } } }
/// <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]); } } }
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); } } }
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]); } }
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]); } }
/// <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]); } }
/// <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))); }
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; }
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); }