public FloatImage Convolve(T image, FloatImage kernel) { var kw = kernel.Width; var kh = kernel.Height; var kxs = kw >> 1; var kys = kh >> 1; var r = new FloatImage(image.Width, image.Height); float total = kernel.Sum(); for (var dy = 0; dy < image.Height; dy++) { for (var dx = 0; dx < image.Width; dx++) { var v = 0f; var sum = 0f; for (var ky = 0; ky < kh; ky++) { var sy = dy + ky - kys; if (sy < 0 || image.Height <= sy) { continue; } for (var kx = 0; kx < kh; kx++) { var sx = dx + kx - kxs; if (sx < 0 || image.Width <= sx) { continue; } var sv = image[sx, sy]; var kv = kernel[kx, ky]; v += sv * kv; sum += kv; } } r[dx, dy] = total == sum ? v : (v * total / sum); } } return(r); }
unsafe public static FloatImage FrameToFloatImage(Frame frame) { OniFrame * frameHandle = (OniFrame *)frame.Handle; int width = (*frameHandle).width; int height = (*frameHandle).height; FloatImage img = new FloatImage(width, height); short *source = (short *)(*frameHandle).data; for (int y = 0; y < height; y++) { short *sourceLine = source + y * width; for (int x = 0; x < width; x++) { img[y, x] = (float)(*sourceLine++); } } return(img); }
private static void Capture(TriggeredStereoCamera cam, out FloatImage left, out FloatImage right, ref int cnt) { cam.Update(); cnt++; FloatCameraImage leftCamImg = cam.CalcChannel(ChannelNames.Left).ToFloatCameraImage(); FloatCameraImage rightCamImg = cam.CalcChannel(ChannelNames.Right).ToFloatCameraImage(); long ts_l = leftCamImg.TimeStamp; long ts_r = rightCamImg.TimeStamp; int fn_l = leftCamImg.FrameNumber; int fn_r = rightCamImg.FrameNumber; unsafe { left = new FloatImage(leftCamImg.Width, leftCamImg.Height, leftCamImg.AbandonDataBuffer()); right = new FloatImage(rightCamImg.Width, rightCamImg.Height, rightCamImg.AbandonDataBuffer()); } left.TimeStamp = ts_l; right.TimeStamp = ts_r; left.FrameNumber = fn_l; right.FrameNumber = fn_r; }
/// <summary> /// compute dct robust image hash /// </summary> /// <param name="image">An image to compute DCT hash.</param> /// <returns>hash of type ulong</returns> public static ulong ComputeDctHash(IByteImage image) { var img = image.Convolve(new FloatImage(7, 7, 1)); var resized = img.Resize(32, 32); var coeff = _DctMatrix ?? (_DctMatrix = CreateDctMatrix(32)); var dctImage = coeff.MatrixMultiply(resized).MatrixMultiply(coeff, isTransposed: true); var median = GetMedianOf64(dctImage); var r = 0ul; for (var y = 0; y < 8; y++) { for (var x = 0; x < 8; x++) { r |= dctImage[x + 1, y + 1] > median ? (1ul << (x + 8 * y)) : 0; } } return(r); }
private void reduce() { if (inputImage != null) { Stopwatch sw = new Stopwatch(); sw.Start(); Bitmap bmp; ColorReduction.Reduce(inputImage, out bmp, textParam.Text); sw.Stop(); float elapsed = 1.0e-3f * sw.ElapsedMilliseconds; SetImage((Bitmap)bmp.Clone()); // Image differences: FloatImage a = new FloatImage(inputImage, 1); FloatImage b = new FloatImage(bmp, 1); // Simple differences: float dr = a.MAD(b, 0); float dg = a.MAD(b, 1); float db = a.MAD(b, 2); float diff = (dr + dg + db) / 3.0f; float diffw = (dr * Draw.RED_WEIGHT + dg * Draw.GREEN_WEIGHT + db * Draw.BLUE_WEIGHT) / Draw.WEIGHT_TOTAL; // Conical blur differences: a.Blur(); b.Blur(); dr = a.MAD(b); MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "Image: {5}x{6} ({7}){0}Time: {1:f3}s{0}plain MAD: {2:f5}{0}weighted MAD: {3:f5}{0}filtered MAD: {4:f5}", Environment.NewLine, elapsed, diff, diffw, dr, inputImage.Width, inputImage.Height, inputImage.PixelFormat.ToString()), "MAE Difference"); bmp.Dispose(); } StopComputation(); }
/// <summary> /// Compute a mask representing pixels that are similiar to the current average pixels computed /// with acc32/count /// </summary> /// <param name="depth"></param> /// <param name="acc32"></param> /// <param name="count32"></param> /// <returns></returns> public static ByteImage DiffMask(ShortImage depthIm, FloatImage acc32, int count, float delta) { ByteImage depthMask = new ByteImage(depthIm.Width, depthIm.Height); // all values zero by default for (int r = 0; r < depthIm.Height; r++) { for (int c = 0; c < depthIm.Width; c++) { ushort depthVal = depthIm[c, r]; float depthAvgVal = acc32[c, r] / count; float diff = Math.Abs(depthVal - depthAvgVal); if (diff < delta) { depthMask[c, r] = 1; } } } return(depthMask); }
public void GetMedianOf64Test(int seed) { var r = new Random(seed); var img = new FloatImage(9, 9); var list = new List <float>(64); for (var c = 0; c < 100; c++) { list.Clear(); for (int y = 1; y <= 8; y++) { for (int x = 1; x <= 8; x++) { var v = (float)r.NextDouble(); img[x, y] = v; list.Add(v); } } list.Sort(); Assert.Equal(list[31], ImagePhash.GetMedianOf64(img)); } }
/// <summary> /// compute the feature vector from a radon projection map. /// </summary> /// <param name="projections">Projections struct</param> /// <returns>Features struct</returns> internal static float[] ComputeFeatureVector(Projections projections) { FloatImage map = projections.Region; int[] ppl = projections.PixelsPerLine; int N = ppl.Length; int D = map.Height; float[] fv = new float[N]; float sum = 0f; float sum_sqd = 0f; for (int k = 0; k < N; k++) { float line_sum = 0f; float line_sum_sqd = 0f; int nb_pixels = ppl[k]; for (int i = 0; i < D; i++) { line_sum += map[k, i]; line_sum_sqd += map[k, i] * map[k, i]; } fv[k] = (float)(nb_pixels > 0 ? (line_sum_sqd / nb_pixels) - (line_sum * line_sum) / (nb_pixels * nb_pixels) : 0); sum += fv[k]; sum_sqd += fv[k] * fv[k]; } float mean = sum / N; float var = 1 / MathF.Sqrt((sum_sqd / N) - (sum * sum) / (N * N)); for (int i = 0; i < N; i++) { fv[i] = (fv[i] - mean) * var; } return(fv); }
public static void NonMaximumSuppression(FloatImage src, FloatImage dest, FloatImage direction, float dirScale) { VisionLabPINVOKE.NonMaximumSuppression__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), FloatImage.getCPtr(direction), dirScale); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void LocalMinFilter(FloatImage src, FloatImage dest, float backGround, FixEdge edge, Mask_Int32 mask) { VisionLabPINVOKE.LocalMinFilter__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), backGround, (int)edge, Mask_Int32.getCPtr(mask)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void GaussianFilter(FloatImage image, double sigma, int size) { VisionLabPINVOKE.GaussianFilter__SWIG_10(FloatImage.getCPtr(image), sigma, size); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void DiskShape(FloatImage image, XYCoord centre, double r, float value) { VisionLabPINVOKE.DiskShape__SWIG_11(FloatImage.getCPtr(image), XYCoord.getCPtr(centre), r, value); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static HoughLine FindFastBestLine(FloatImage src, HLParams p, float edgeMin) { HoughLine ret = new HoughLine(VisionLabPINVOKE.FindFastBestLine__SWIG_5(FloatImage.getCPtr(src), HLParams.getCPtr(p), edgeMin), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static HoughCircle FindBestCircle(FloatImage src, double minR, double maxR, double deltaR) { HoughCircle ret = new HoughCircle(VisionLabPINVOKE.FindBestCircle__SWIG_5(FloatImage.getCPtr(src), minR, maxR, deltaR), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
internal static HandleRef getCPtr(FloatImage obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
public static FloatImage Convolve(this IByteImage image, FloatImage kernel) => image.Wrap().Convolve(kernel);
public static FloatImage Blur(this IByteImage image, float sigma) => image.Convolve(FloatImage.CreateGaussian(3, sigma));
internal static FloatImage Convolve(this IByteImageWrapper image, FloatImage kernel) => image.GetOperations().Convolve(image, kernel);
/// <summary> /// Tone-mapping of the input HDR image. /// </summary> /// <param name="input">Mandatory HDR image.</param> /// <param name="result">Optional (pre-allocatied) output LDR image.</param> /// <param name="param">Optional text parameters (from form's text-field).</param> /// <returns>Output LDR image (use pre-allocated 'result' if possible).</returns> public static unsafe Bitmap ToneMap(FloatImage input, Bitmap result, string param) { if (input == null) { return(null); } // {{ TODO: write your own tone-mapping reduction code here // custom parameters from the text-field: Dictionary <string, string> p = Util.ParseKeyValueList(param); double g = 0.0; if (p.Count > 0) { // gamma=<float-number> if (Util.TryParse(p, "gamma", ref g) && g > 0.001 && Math.Abs(g - 1.0) > 0.001) { g = 1.0 / g; } else { g = 0.0; } } int width = input.Width; int height = input.Height; // re-allocate the output image if necessary: if (result == null || result.Width != width || result.Height != height || result.PixelFormat != PixelFormat.Format24bppRgb) { result = new Bitmap(width, height, PixelFormat.Format24bppRgb); } // input range: double minY, maxY; input.Contrast(out minY, out maxY); double coef = 1.0 / maxY; // the whole range is mapped into (0.0,1.0> BitmapData dataOut = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); fixed(float *id = input.Data) { float *iptr; byte * optr; int dO = Image.GetPixelFormatSize(PixelFormat.Format24bppRgb) / 8; // BGR for (int y = 0; y < height; y++) { iptr = id + input.Scan0 + y * input.Stride; optr = (byte *)dataOut.Scan0 + y * dataOut.Stride; if (g > 0.0) { for (int x = 0; x++ < width; iptr += input.Channels, optr += dO) { optr[2] = (byte)Arith.Clamp(255.999 * Math.Pow(iptr[0] * coef, g), 0.0, 255.0); optr[1] = (byte)Arith.Clamp(255.999 * Math.Pow(iptr[1] * coef, g), 0.0, 255.0); optr[0] = (byte)Arith.Clamp(255.999 * Math.Pow(iptr[2] * coef, g), 0.0, 255.0); } } else { for (int x = 0; x++ < width; iptr += input.Channels, optr += dO) { optr[2] = (byte)Arith.Clamp(255.999 * iptr[0] * coef, 0.0, 255.0); optr[1] = (byte)Arith.Clamp(255.999 * iptr[1] * coef, 0.0, 255.0); optr[0] = (byte)Arith.Clamp(255.999 * iptr[2] * coef, 0.0, 255.0); } } } } result.UnlockBits(dataOut); // }} return(result); }
FloatImage IByteImageOperations.Convolve(IByteImageWrapper image, FloatImage kernel) => Convolve((T)image, kernel);
public static void VarianceFilter(FloatImage src, FloatImage dest, FixEdge edge, Mask_Int32 mask) { VisionLabPINVOKE.VarianceFilter__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), (int)edge, Mask_Int32.getCPtr(mask)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void HoughCircleT(FloatImage src, double minR, double maxR, double deltaR, vector_FloatImage destTab) { VisionLabPINVOKE.HoughCircleT__SWIG_5(FloatImage.getCPtr(src), minR, maxR, deltaR, vector_FloatImage.getCPtr(destTab)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public FloatImage(FloatImage image) : this(VisionLabPINVOKE.new_FloatImage__SWIG_3(FloatImage.getCPtr(image)), true) { if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } }
public static vector_HoughCircle FindFastBestCircles(FloatImage src, CircleBrightness brightness, float edgeMin, double minR, double maxR, double deltaR) { vector_HoughCircle ret = new vector_HoughCircle(VisionLabPINVOKE.FindFastBestCircles__SWIG_23(FloatImage.getCPtr(src), (int)brightness, edgeMin, minR, maxR, deltaR), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public double ClassifyOutputTab(FloatImage image, vector_ClassOutput outputTab) { double ret = VisionLabPINVOKE.BPN_ImageClassifier_Float_ClassifyOutputTab(swigCPtr, FloatImage.getCPtr(image), vector_ClassOutput.getCPtr(outputTab)); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// Converts the given image into B/W (1bpp) output suitable for high-resolution printer. /// </summary> /// <param name="input">Input image.</param> /// <param name="output">Output (1bpp) image.</param> /// <param name="oWidth">Default output image width in pixels.</param> /// <param name="oHeight">Default output image height in pixels.</param> /// <param name="param">Set of optional text parameters.</param> /// <returns>Number of dots printed.</returns> public static long TransformImage(Bitmap input, out Bitmap output, int oWidth, int oHeight, string param) { // !!!{{ TODO: write your own image dithering code here int iWidth = input.Width; int iHeight = input.Height; long dots = 0L; // custom parameters from the text-field: double randomness = 0.0; double dot = 0.0; double gamma = 0.0; bool sampling = false; Dictionary <string, string> p = Util.ParseKeyValueList(param); if (p.Count > 0) { double scale = 0.0; // scale=<float-number> if (Util.TryParse(p, "scale", ref scale) && scale > 0.01) { oWidth = (int)(iWidth * scale); oHeight = (int)(iHeight * scale); } // rnd=<float-number> if (Util.TryParse(p, "rnd", ref randomness)) { randomness = Arith.Clamp(randomness, 0.0, 1.0); } // dot=<float-number> if (Util.TryParse(p, "dot", ref dot)) { dot = Math.Max(dot, 0.0); } // gamma=<float-number> if (Util.TryParse(p, "gamma", ref gamma)) { gamma = Math.Max(gamma, 0.0); } // sampling=<bool> Util.TryParse(p, "sampling", ref sampling); } // create output 1bpp Bitmap output = new Bitmap(oWidth, oHeight, PixelFormat.Format1bppIndexed); float dx = (iWidth - 1.0f) / (oWidth - 1.0f); float dy = (iHeight - 1.0f) / (oHeight - 1.0f); // set the B/W palette (0 .. black, 1 .. white): ColorPalette pal = output.Palette; pal.Entries[0] = Color.Black; pal.Entries[1] = Color.White; output.Palette = pal; int x, y; float fx, fy; RandomJames rnd = new RandomJames(); // convert pixel data (fast memory-mapped code): PixelFormat iFormat = input.PixelFormat; if (!PixelFormat.Format24bppRgb.Equals(iFormat) && !PixelFormat.Format32bppArgb.Equals(iFormat) && !PixelFormat.Format32bppPArgb.Equals(iFormat) && !PixelFormat.Format32bppRgb.Equals(iFormat)) { iFormat = PixelFormat.Format24bppRgb; } BitmapData dataOut = output.LockBits(new Rectangle(0, 0, oWidth, oHeight), ImageLockMode.WriteOnly, output.PixelFormat); unsafe { byte *optr; // A. placing reasonable number of random dots on the paper if (sampling) { dot = Math.Max(dot, 1.0); // clear output image: optr = (byte *)dataOut.Scan0; for (x = 0; x++ < oHeight * dataOut.Stride;) { *optr++ = 255; } // create grayscale image able to sample points from itself: FloatImage fi = new FloatImage(input); fi = fi.GrayImage(true, gamma); fi.PrepareCdf(); // sample 'dots' random dots: dots = (long)(1.2 * oWidth * oHeight / (dot * dot)); double xx, yy; for (long i = 0; i++ < dots;) { fi.GetSample(out xx, out yy, rnd.UniformNumber(), rnd); xx = oWidth * (xx / iWidth); yy = oHeight * (yy / iHeight); Dot1bpp((int)xx, (int)yy, dot, dataOut); } } else { BitmapData dataIn = input.LockBits(new Rectangle(0, 0, iWidth, iHeight), ImageLockMode.ReadOnly, iFormat); // B. random screen using dots bigger than 1px if (dot > 0.0) { // clear output image: optr = (byte *)dataOut.Scan0; for (x = 0; x++ < oHeight * dataOut.Stride;) { *optr++ = 255; } int dI = Image.GetPixelFormatSize(iFormat) / 8; for (y = 0, fy = 0.0f; y < oHeight; y++, fy += dy) { if (!Form1.cont) { break; } for (x = 0, fx = 0.0f; x < oWidth; x++, fx += dx) { float gray = GetGray(fx, fy, dataIn, dI); if (gamma > 0.0) { gray = (float)Math.Pow(gray, gamma); } float threshold = (float)(0.5 - randomness * (rnd.UniformNumber() - 0.5)); if (gray < threshold) { dots++; Dot1bpp(x, y, dot, dataOut); } } } } else // C. random screen using individual pixels { int buffer; int dI = Image.GetPixelFormatSize(iFormat) / 8; for (y = 0, fy = 0.0f; y < oHeight; y++, fy += dy) { if (!Form1.cont) { break; } optr = (byte *)dataOut.Scan0 + y * dataOut.Stride; buffer = 0; for (x = 0, fx = 0.0f; x < oWidth; fx += dx) { float gray = GetGray(fx, fy, dataIn, dI); if (gamma > 0.0) { gray = (float)Math.Pow(gray, gamma); } float threshold = (float)(0.5 - randomness * (rnd.UniformNumber() - 0.5)); buffer += buffer; if (gray >= threshold) { buffer++; } else { dots++; } if ((++x & 7) == 0) { *optr++ = (byte)buffer; buffer = 0; } } // finish the last byte of the scanline: if ((x & 7) != 0) { while ((x++ & 7) != 0) { buffer += buffer; } *optr = (byte)buffer; } } } input.UnlockBits(dataIn); } output.UnlockBits(dataOut); } return(dots); // !!!}} }
public double EvaluateImage(FloatImage image, int classExp, ref int classRes, ref double confidency, vector_double output) { double ret = VisionLabPINVOKE.BPN_ImageClassifier_Float_EvaluateImage(swigCPtr, FloatImage.getCPtr(image), classExp, ref classRes, ref confidency, vector_double.getCPtr(output)); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public double TrainImage(double learnRate, double momentum, FloatImage image, int classNr) { double ret = VisionLabPINVOKE.BPN_ImageClassifier_Float_TrainImage(swigCPtr, learnRate, momentum, FloatImage.getCPtr(image), classNr); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatImage obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public static void DeConvolution(FloatImage image, FloatImage psf, double k) { VisionLabPINVOKE.DeConvolution__SWIG_5(FloatImage.getCPtr(image), FloatImage.getCPtr(psf), k); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public bool GetImage(string imageName, FloatImage image) { bool ret = VisionLabPINVOKE.VisLibCmdInt_GetImage__SWIG_5(swigCPtr, imageName, FloatImage.getCPtr(image)); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static void InterpolateAtSpecificPixel(FloatImage src, FloatImage dest, float value) { VisionLabPINVOKE.InterpolateAtSpecificPixel__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), value); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
static public void Evaluate() { wasEvaluated = true; try { using (TextWriter wri = new StreamWriter(Path.Combine(EvalOptions.options.outDir, EvalOptions.options.outputFileName), false, Encoding.UTF8)) { string part; // compile all source files: if (!wasCompiled) { Options.Log(null); CompileSources(EvalOptions.options.sourceFiles); wasCompiled = true; } int images = EvalOptions.options.inputFiles.Count; Console.WriteLine(Options.LogFormat("Configuration - assemblies: {0}, bans: {1}, best: {2}, images: {3}, output: '{4}'", assemblies.Count, EvalOptions.options.bans.Count, EvalOptions.options.best.Count, images, EvalOptions.options.outputFileName)); // HTML file header: if (Util.ReadTextFile(EvalOptions.options.headerFile, out part)) { wri.Write(part); } wri.WriteLine("<table class=\"nb\">"); wri.WriteLine("<tr><th>Name</th><th>Time</th><th>Image</th></tr>"); int ord = 0; foreach (var imageFn in EvalOptions.options.inputFiles) { wri.WriteLine("<tr><td> </td></tr>"); string relative = EvalOptions.options.imageLocal ? Path.GetFileName(imageFn) : Util.MakeRelativePath(EvalOptions.options.outDir, imageFn); string relativeLDR = relative.Replace(".hdr", ".jpg"); string[] desctiption; EvalOptions.options.imageInfo.TryGetValue(Path.GetFileName(imageFn), out desctiption); wri.WriteLine("<tr><td colspan=\"2\" class=\"b p r\">{0}</td>", (desctiption == null) ? " " : string.Join(", ", desctiption)); wri.WriteLine($"<td><a href=\"{relative}\"><img src=\"{relativeLDR}\" width=\"{EvalOptions.options.imageWidth}\" alt=\"input\" /></a></td>"); wri.WriteLine("</tr>"); FloatImage image = RadianceHDRFormat.FromFile(imageFn); Options.LogFormatMode("debug", "Input image '{0}':", imageFn); qtime.Clear(); List <string> names = new List <string>(assemblies.Keys); names.Sort(); string outBase = Path.Combine(EvalOptions.options.outDir, Path.GetFileNameWithoutExtension(imageFn)); foreach (var name in names) { if (!EvalOptions.options.bans.Contains(name) && (!EvalOptions.options.bestOnly || EvalOptions.options.best.Contains(name))) { EvaluateSolution(name, assemblies[name], image, outBase, wri); } } wri.Write(string.Format(CultureInfo.InvariantCulture, "<tr><th class=\"l\">Time [s]</th><td class=\"p t r\">{0:f2}s</td>", qtime.Mean)); wri.WriteLine(string.Format(CultureInfo.InvariantCulture, "<td class=\"p\">+-{0:f2}s, quartiles: {1:f2} - {2:f2} - {3:f2} - {4:f2} - {5:f2}</td></tr>", qtime.Variance, qtime.Min, qtime.Quartile(1), qtime.Median, qtime.Quartile(3), qtime.Max)); Console.WriteLine(Options.LogFormat("Finished image #{0}/{1} '{2}'", ++ord, images, relative)); } wri.WriteLine("</table>"); // HTML file footer: if (Util.ReadTextFile(EvalOptions.options.footerFile, out part)) { wri.Write(part); } } } catch (IOException e) { Console.WriteLine(Options.LogFormat("I/O error: {0}", e.Message)); } }
public static void LoGFilter(FloatImage image, double sigma) { VisionLabPINVOKE.LoGFilter__SWIG_11(FloatImage.getCPtr(image), sigma); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
static void EvaluateSolution(string name, Assembly ass, FloatImage image, string outBase, TextWriter wri) { string name2 = null; string param = null; Bitmap ldr = null; // memory cleanup and report: long memOccupied = GC.GetTotalMemory(true); Process procObj = Process.GetCurrentProcess(); Options.LogFormatMode("debug", $"Evaluating '{name}' [{(memOccupied >> 20)}M - {(procObj.PrivateMemorySize64 >> 20)}M - {(procObj.VirtualMemorySize64 >> 20)}M - {(procObj.WorkingSet64 >> 20)}M - {(procObj.PagedMemorySize64 >> 20)}M - {(procObj.PagedSystemMemorySize64 >> 10)}K - {(procObj.NonpagedSystemMemorySize64 >> 10)}K]"); string msg = null; // running the solution function: sw.Restart(); try { // call #1: default params, name object[] arguments1 = new object[] { null, null }; Type classType = ass.GetType("tmap" + name + ".ToneMapping"); classType.GetMethod("InitParams").Invoke(null, arguments1); param = arguments1[0].ToString(); name2 = arguments1[1].ToString(); // call #2: the actual tone-mapping task object[] arguments2 = new object[] { image, null, param ?? "" }; ldr = (Bitmap)classType.GetMethod("ToneMap").Invoke(null, arguments2); } catch (Exception e) { msg = (e.InnerException ?? e).Message; } sw.Stop(); // quantile statistics for elapsed time and color variance double elapsed = sw.ElapsedMilliseconds * 0.001; // report: if (string.IsNullOrEmpty(name2) || name2 == "pilot") { name2 = name; } bool best = EvalOptions.options.best.Contains(name); wri.Write(string.Format(CultureInfo.InvariantCulture, "<tr><td class=\"t\">{0}{1}{2}</td><td class=\"p t r\">{3:f2}s</td>", best ? "<b>" : "", name2, best ? "</b>" : "", elapsed)); if (!string.IsNullOrEmpty(msg) || ldr == null) { Util.Log($"Error: '{msg ?? "no image"}'"); wri.WriteLine($"<td>Error: {msg ?? "no image"}</td>"); wri.WriteLine("</tr>"); if (ldr != null) { ldr.Dispose(); } return; } // output LDR image: qtime.Add(elapsed); string ldrName = outBase + name + ".png"; ldr.Save(ldrName, ImageFormat.Png); ldr.Dispose(); wri.WriteLine($"<td><img src=\"{Path.GetFileName(ldrName)}\" width=\"{EvalOptions.options.imageWidth}\" alt=\"{name}\" /></td>"); wri.WriteLine("</tr>"); }
public static void SNN_MedianFilter(FloatImage src, FloatImage dest, float radius, FixEdge edge) { VisionLabPINVOKE.SNN_MedianFilter__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), radius, (int)edge); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
private void backgroundWorkerGetFrames_DoWork(object sender, DoWorkEventArgs e) { while (!backgroundWorkerGetFrames.CancellationPending) { // capture a new frame try { //cam.Invoke("StartStreams", null); cam.Update(); //cam.Invoke("StopStreams", null); } catch (Exception ex) { GC.KeepAlive(ex); cam = new CameraClient("192.168.1.72", 8081, 8082, "MetriCam2.Cameras.Kinect2", "MetriCam2.Cameras.Kinect2"); cam.Connect(); //cam.Invoke("StopStreams", null); } Point3fImage p3Image = null; if (channel3DName == ChannelNames.Point3DImage) { Point3fCameraImage image3D = (Point3fCameraImage)cam.CalcChannel(ChannelNames.Point3DImage); p3Image = new Point3fImage(ref image3D); } else if (channel3DName == ChannelNames.Distance || channel3DName == ChannelNames.ZImage) { FloatCameraImage image3D = (FloatCameraImage)cam.CalcChannel(channel3DName); p3Image = new Point3fImage(new FloatImage(ref image3D), projectiveTransformation, channel3DName == ChannelNames.ZImage); } FloatImage ir = ConvertToFloatImage(cam.CalcChannel(channel2DName).ToFloatCameraImage()); Bitmap bitmap = ir.ToBitmap(); //secondBitmap = zImage.ToBitmap(); // set the picturebox-bitmap in the main thread to avoid concurrency issues (a few helper methods required, easier/nicer solutions welcome). this.InvokeSetBmp(bitmap); MaskImage mask = new MaskImage(p3Image.Width, p3Image.Height); ir = ir.Normalize(); for (int y = 0; y < mask.Height; y++) { for (int x = 0; x < mask.Width; x++) { Point3f p = p3Image[y, x]; if (p.X > -99f && p.X < 99f && p.Y > -99f & p.Y < 99f && p.Z > 0 && p.Z < 99f) { mask[y, x] = 0xff; } } } p3Image.EliminateFlyingPixels(5, 0.005f, 0.2f); p3Image.Mask = mask; TriangleIndexList til = new TriangleIndexList(p3Image, false, true); if (renderTil == null) { renderTil = new Metri3D.Objects.RenderTriangleIndexList(til, Color.White); panel3D.AddRenderObject(renderTil); } else { renderTil.UpdateData(til, Color.White); } panel3D.Invalidate(); } }
public static void ZeroCrossings(FloatImage src, FloatImage dest) { VisionLabPINVOKE.ZeroCrossings__SWIG_11(FloatImage.getCPtr(src), FloatImage.getCPtr(dest)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void Extract1Channel(HSV161616Image image, HSVColor plane, FloatImage chan) { VisionLabPINVOKE.Extract1Channel__SWIG_72(HSV161616Image.getCPtr(image), (int)plane, FloatImage.getCPtr(chan)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void FastHoughCircleT(FloatImage src, CircleBrightness brightness, float edgeMin, double minR, double maxR, double deltaR, vector_FloatImage destTab) { VisionLabPINVOKE.FastHoughCircleT__SWIG_5(FloatImage.getCPtr(src), (int)brightness, edgeMin, minR, maxR, deltaR, vector_FloatImage.getCPtr(destTab)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void NormaliseHue(HSV161616Image src, short hue, short minVal, short minSat, FloatImage dest) { VisionLabPINVOKE.NormaliseHue__SWIG_9(HSV161616Image.getCPtr(src), hue, minVal, minSat, FloatImage.getCPtr(dest)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static vector_HoughCircle FindBestCircles(FloatImage src, double minR, double maxR, double deltaR, int nrCircles) { vector_HoughCircle ret = new vector_HoughCircle(VisionLabPINVOKE.FindBestCircles__SWIG_22(FloatImage.getCPtr(src), minR, maxR, deltaR, nrCircles), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static void BlockPattern(FloatImage image, XYCoord leftTop, int height, int width, float value, int repeatx, int repeaty) { VisionLabPINVOKE.BlockPattern__SWIG_11(FloatImage.getCPtr(image), XYCoord.getCPtr(leftTop), height, width, value, repeatx, repeaty); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void FastHoughLineT(FloatImage src, HLParams p, float edgeMin, FloatImage dest) { VisionLabPINVOKE.FastHoughLineT__SWIG_5(FloatImage.getCPtr(src), HLParams.getCPtr(p), edgeMin, FloatImage.getCPtr(dest)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static int CountPixel(FloatImage image, float value) { int ret = VisionLabPINVOKE.CountPixel__SWIG_5(FloatImage.getCPtr(image), value); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static vector_HoughLine FindFastBestLines(FloatImage src, HLParams p, float edgeMin, int nrLines, double minR, double minPhi, int minHits) { vector_HoughLine ret = new vector_HoughLine(VisionLabPINVOKE.FindFastBestLines__SWIG_5(FloatImage.getCPtr(src), HLParams.getCPtr(p), edgeMin, nrLines, minR, minPhi, minHits), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public FloatImage Blur(double sigma) => Convolve(FloatImage.CreateGaussian(3, sigma));
public static void NormaliseHue(HSV888Image src, byte hue, byte minVal, byte minSat, FloatImage dest, float notNormalised) { VisionLabPINVOKE.NormaliseHue__SWIG_6(HSV888Image.getCPtr(src), hue, minVal, minSat, FloatImage.getCPtr(dest), notNormalised); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public int AddImage(string className, FloatImage image) { int ret = VisionLabPINVOKE.ClassFeatureSet_Float_AddImage(swigCPtr, className, FloatImage.getCPtr(image)); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static void AddBorder(FloatImage src, FloatImage dest, int top, int left, int right, int bottom, float value) { VisionLabPINVOKE.AddBorder__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), top, left, right, bottom, value); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void Sobel(FloatImage src, FloatImage destMag, FloatImage destDir) { VisionLabPINVOKE.Sobel__SWIG_23(FloatImage.getCPtr(src), FloatImage.getCPtr(destMag), FloatImage.getCPtr(destDir)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void CircleShape(FloatImage image, XYCoord centre, int r, float value, ZeroOrOriginal zorg) { VisionLabPINVOKE.CircleShape__SWIG_10(FloatImage.getCPtr(image), XYCoord.getCPtr(centre), r, value, (int)zorg); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void MarrHildreth(FloatImage src, FloatImage dest, double sigmaGaussian, double sigmaLoG, float minEdge) { VisionLabPINVOKE.MarrHildreth__SWIG_5(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), sigmaGaussian, sigmaLoG, minEdge); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void DeInterlace(FloatImage image) { VisionLabPINVOKE.DeInterlace__SWIG_5(FloatImage.getCPtr(image)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static void Convolution(FloatImage src, FloatImage dest, int divideFactor, FixEdge edge, Mask_Int32 mask) { VisionLabPINVOKE.Convolution__SWIG_11(FloatImage.getCPtr(src), FloatImage.getCPtr(dest), divideFactor, (int)edge, Mask_Int32.getCPtr(mask)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
/// <summary> /// Find radon projections of N lines running through the image center for lines angled 0 to 180 degrees from horizontal. /// </summary> /// <param name="img">CImg src image</param> /// <param name="numberOfLines">int number of angled lines to consider.</param> /// <returns>Projections struct</returns> internal static Projections FindRadonProjections(FloatImage img, int numberOfLines) { var width = img.Width; var height = img.Height; int D = (width > height) ? width : height; var x_center = width / 2f; var y_center = height / 2f; var x_off = (int)MathF.Floor(x_center + GetRoundingFactor(x_center)); var y_off = (int)MathF.Floor(y_center + GetRoundingFactor(y_center)); var projs = new Projections(numberOfLines, D, numberOfLines); var radonMap = projs.Region; var ppl = projs.PixelsPerLine; for (var k = 0; k < numberOfLines / 4 + 1; k++) { var theta = k * MathF.PI / numberOfLines; var alpha = MathF.Tan(theta); for (var x = 0; x < D; x++) { var y = alpha * (x - x_off); var yd = (int)MathF.Floor(y + GetRoundingFactor(y)); if ((yd + y_off >= 0) && (yd + y_off < height) && (x < width)) { radonMap[k, x] = img[x, yd + y_off]; ppl[k] += 1; } if ((yd + x_off >= 0) && (yd + x_off < width) && (k != numberOfLines / 4) && (x < height)) { radonMap[numberOfLines / 2 - k, x] = img[yd + x_off, x]; ppl[numberOfLines / 2 - k] += 1; } } } var j = 0; for (var k = 3 * numberOfLines / 4; k < numberOfLines; k++) { var theta = k * MathF.PI / numberOfLines; var alpha = MathF.Tan(theta); for (var x = 0; x < D; x++) { var y = alpha * (x - x_off); var yd = (int)MathF.Floor(y + GetRoundingFactor(y)); if ((yd + y_off >= 0) && (yd + y_off < height) && (x < width)) { radonMap[k, x] = img[x, yd + y_off]; ppl[k] += 1; } if ((y_off - yd >= 0) && (y_off - yd < width) && (2 * y_off - x >= 0) && (2 * y_off - x < height) && (k != 3 * numberOfLines / 4)) { radonMap[k - j, x] = img[-yd + y_off, -(x - y_off) + y_off]; ppl[k - j] += 1; } } j += 2; } return(projs); }
public static void Correlation(FloatImage image, FloatImage mask) { VisionLabPINVOKE.Correlation__SWIG_5(FloatImage.getCPtr(image), FloatImage.getCPtr(mask)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
static void Main(string[] args) { MetriLog log = new MetriLog(); Random rand = new Random(); const int MAX_DELAY_IN_MIN = 20; Camera leftCam = new TheImagingSource(); Camera rightCam = new TheImagingSource(); SerialPort triggerPort = new SerialPort("COM7", 9600); TriggeredStereoCamera cam = new TriggeredStereoCamera(leftCam, rightCam, triggerPort); FloatImage left, leftOld = null, right, rightOld = null; float thres; // thres = 1000.0f; // uEye thres = 100000.0f; // TIS int cnt = 0; const float MAX_EXPOSURE = 10f; const float DARK_THRES = 50f; // uEye: 10f, TIS: 50f const int NUM_WARMUP_IMAGES = 50; ConfigureLogging(StressTests.Freeze.Resources.LoggingConfigInfo); log.SetLogFile(@"D:\temp\stress_test_TIS.log"); cam.Connect(); cam.Exposure = 4; log.Info("Warming up."); for (int i = 0; i < NUM_WARMUP_IMAGES; i++) { Capture(cam, out left, out right, ref cnt); } log.Info("Starting test."); bool running = true; while (running) { log.Debug("Another round starts."); for (int i = 0; i < 10; i++) { if (cam.Exposure > MAX_EXPOSURE) { cam.Exposure = MAX_EXPOSURE; leftOld = null; rightOld = null; continue; } Capture(cam, out left, out right, ref cnt); float minL, maxL, minR, maxR; left.GetMinMax(out minL, out maxL); right.GetMinMax(out minR, out maxR); log.Debug("MAX = " + maxL + " " + maxR); if (maxL == 255f || maxR == 255f) { log.Info("Overexposed, reducing exposure time."); cam.Exposure = cam.Exposure * (3f / 4f); leftOld = null; rightOld = null; continue; } if (maxL < DARK_THRES && maxR < DARK_THRES) { if (cam.Exposure < MAX_EXPOSURE) { log.Info("Underexposed, increasing exposure time."); cam.Exposure = cam.Exposure * (4f / 3f); leftOld = null; rightOld = null; continue; } log.Info("seems to be dark, let's sleep an hour."); Thread.Sleep(1000 * 60 * 60); leftOld = null; rightOld = null; continue; } rightOld = Compare(right, rightOld, thres, cnt, "R", log); leftOld = Compare(left, leftOld, thres, cnt, "L", log); if (null == leftOld || null == rightOld) { break; } } int random = rand.Next(100); float delayInMinutes = (float)random / 100f * (float)MAX_DELAY_IN_MIN; log.Debug("Sleeping for " + delayInMinutes + " minutes"); Thread.Sleep((int)(1000 * 60 * delayInMinutes)); //Thread.Sleep(500); } cam.Disconnect(); }
private unsafe static Bitmap ToBitmap(FloatImage img) { if (img.Data == null) { return(null); } float maxVal = float.MinValue; float minVal = float.MaxValue; fixed(float *imgData = img.Data) { for (int y = 0; y < img.Height; y++) { float *dataPtr = imgData + y * img.Width; for (int x = 0; x < img.Width; x++) { float val = *dataPtr++; if (val > maxVal) { maxVal = val; } if (val < minVal) { minVal = val; } } } maxVal = 0.9f * maxVal; for (int y = 0; y < img.Height; y++) { float *dataPtr = imgData + y * img.Width; for (int x = 0; x < img.Width; x++) { if (*dataPtr > maxVal) { *dataPtr = maxVal; } dataPtr++; } } Bitmap bitmap = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); if (maxVal == minVal) { // avoid division by zero. return(bitmap); } Rectangle rect = new Rectangle(0, 0, img.Width, img.Height); BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); byte * bmpPtr = (byte *)bitmapData.Scan0; for (int y = 0; y < img.Height; y++) { byte * linePtr = bmpPtr + bitmapData.Stride * y; float *dataPtr = imgData + y * img.Width; for (int x = 0; x < img.Width; x++) { byte value = (byte)(byte.MaxValue * (*dataPtr++ - minVal) / (maxVal - minVal)); * linePtr++ = value; * linePtr++ = value; * linePtr++ = value; } } bitmap.UnlockBits(bitmapData); return(bitmap); } }