public override System.Drawing.Bitmap GetAsBmp(float[] rawValues) { ImageFloat img = new ImageFloat(); ImageManipulation.Vector2Image(rawValues, ref img, w, h); return(img.toBmp()); }
public new ImageFloat read() { global::System.IntPtr cPtr = yarpPINVOKE.TypedReaderImageFloat_read__SWIG_1(swigCPtr); ImageFloat ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageFloat(cPtr, false); return(ret); }
public new ImageFloat read(bool shouldWait) { global::System.IntPtr cPtr = yarpPINVOKE.BufferedPortImageFloat_read__SWIG_0(swigCPtr, shouldWait); ImageFloat ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageFloat(cPtr, false); return(ret); }
public new ImageFloat lastRead() { global::System.IntPtr cPtr = yarpPINVOKE.BufferedPortImageFloat_lastRead(swigCPtr); ImageFloat ret = (cPtr == global::System.IntPtr.Zero) ? null : new ImageFloat(cPtr, false); return(ret); }
/// <summary> /// Write the perceived value on the yarp port. /// </summary> public override void WritePerceivedValue() { ImageFloat img = portPerceived.prepare(); ImageManipulation.Vector2Image(PerceivedValue, ref img, w, h); portPerceived.write(); }
public new void onRead(ImageFloat datum) { yarpPINVOKE.TypedReaderCallbackImageFloat_onRead__SWIG_0(swigCPtr, ImageFloat.getCPtr(datum)); if (yarpPINVOKE.SWIGPendingException.Pending) { throw yarpPINVOKE.SWIGPendingException.Retrieve(); } }
public new void onRead(ImageFloat datum, TypedReaderImageFloat reader) { yarpPINVOKE.BufferedPortImageFloat_onRead__SWIG_0_0(swigCPtr, ImageFloat.getCPtr(datum), TypedReaderImageFloat.getCPtr(reader)); if (yarpPINVOKE.SWIGPendingException.Pending) { throw yarpPINVOKE.SWIGPendingException.Retrieve(); } }
/// <summary> /// Read the real value on the yarp port. /// Convert the image into a vector. /// </summary> public override void ReadRealValue() { ImageFloat img = portReal.read(isBlockingRead); if (img != null) { RealValue = ImageManipulation.Image2Vector(Crop(img), w, h); } }
public new static bool write(ImageFloat src, string dest) { bool ret = yarpPINVOKE.write__SWIG_9(ImageFloat.getCPtr(src), dest); if (yarpPINVOKE.SWIGPendingException.Pending) { throw yarpPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public new static bool read(ImageFloat dest, string src) { bool ret = yarpPINVOKE.read__SWIG_9(ImageFloat.getCPtr(dest), src); if (yarpPINVOKE.SWIGPendingException.Pending) { throw yarpPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public new bool write(Bottle data1, ImageFloat data2) { bool ret = yarpPINVOKE.Port_write__SWIG_9(swigCPtr, Bottle.getCPtr(data1), ImageFloat.getCPtr(data2)); if (yarpPINVOKE.SWIGPendingException.Pending) { throw yarpPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
protected ImageFloat Crop(ImageFloat img) { ImageFloat img2 = new ImageFloat(); img2.resize(img.width() - 2 * padding, img.height() - 2 * padding); for (int x = padding; x < img.width() - padding; x++) { for (int y = padding; y < img.height() - padding; y++) { img2.setPixel(x - padding, y - padding, img.getPixel(x, y)); } } return(img2); }
/// <summary> /// Self explicit /// </summary> /// <param name="v"></param> /// <param name="img"></param> public static void Vector2Image(float[] v, ref ImageFloat img, int w, int h) { double t0 = Time.now(); img.resize(w, h); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { img.setPixel(i, j, (float)v[j * w + i] * 255.0f); } } double t1 = Time.now(); //Console.WriteLine("Vector2img : " + (t1 - t0).ToString()); }
public static Bitmap toBmp(this ImageFloat img) { int w = img.width(); int h = img.height(); Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { float px = img.getPixel(x, y); Color color = Color.FromArgb((int)px, (int)px, (int)px); bmp.SetPixel(x, y, color); } } return(bmp); }
/// <summary> /// Self explicit /// </summary> /// <param name="img"></param> /// <returns></returns> public static float[] Image2Vector(ImageFloat img, int w, int h) { ImageFloat img2 = new ImageFloat(); img2.copy(img, w, h); float[] v = new float[w * h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { float px = img2.getPixel(i, j) / 255.0f; v[j * w + i] = px; } } //Console.WriteLine("Image2Vector : " + (t1 - t0).ToString()); return(v); }
public void HoriztonalConvolution_is_correct() { var imageData = new float[, , ] { { { 0, 1, 2 }, { 0, -1, -2 }, { -1, 0, 1 }, { 1, 0, 1 } }, { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 1 } }, { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 1 } }, { { 0, 1, 2 }, { 0, -1, -2 }, { -1, 0, 1 }, { -1, 0, 1 } }, { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 1 } } }; var image = new ImageFloat <RgbImageType>(imageData); var kernel = new float[] { 1, 2, -2, -1 }; var actualResult = image.HorizontalConvolution(kernel, leftOffset: 1); var expectedResult = new float[, , ] { { { 1, 5, 9 }, { 1, -1, -5 }, { -5, -1, -3 }, { -2, 0, 0 } }, { { 3, -2, -1 }, { 1, 2, -3 }, { 0, 1, -1 }, { 0, 0, 0 } }, { { 3, -2, -1 }, { 1, 2, -3 }, { 0, 1, -1 }, { 0, 0, 0 } }, { { 1, 5, 9 }, { 3, -1, -5 }, { 1, -1, -3 }, { 0, 0, 0 } }, { { 3, -2, -1 }, { 1, 2, -3 }, { 0, 1, -1 }, { 0, 0, 0 } } }; Expect(actualResult.Dimensions, Is.EqualTo(image.Dimensions)); for (var i = 0; i < image.Dimensions.X; i++) { for (var j = 0; j < image.Dimensions.Y; j++) { for (var c = 0; c < 3; c++) { Expect(actualResult[new Vector2i(i, j), c], Is.EqualTo(expectedResult[j, i, c]).Within(_tolerance), string.Format("[{0},{1},{2}]", i, j, c)); } } } }
public unsafe static IImageFloat <TType> HorizontalConvolution <TType> (this IReadOnlyImageFloat <TType> @this, float *kernel, int leftOffset, int rightOffset) where TType : IImageType, new() { ArgAssert.AtLeast(leftOffset, "leftOffset", 0); ArgAssert.AtLeast(rightOffset, "rightOffset", 0); var answer = new ImageFloat <TType>(@this.Dimensions); var channelsCount = Singleton <TType> .Instance.ChannelsCount; using (var pinInput = @this.Open()) { var inPtr = pinInput.Ptr; using (var pinOutput = answer.Open()) { var outPtr = pinOutput.Ptr; for (var j = 0; j < @this.Dimensions.Y; j++) { var inPixelPtr = inPtr; var outPixelPtr = outPtr; for (var i = 0; i < @this.Dimensions.X; i++) { int k = -leftOffset; var kernelPtr = kernel; for (; k < -i; k++) { for (var c = 0; c < channelsCount; c++) { outPixelPtr[c] += *kernelPtr * inPtr[c]; } kernelPtr++; } var rightBound = Math.Min(@this.Dimensions.X - i - 1, rightOffset); var windowPtr = inPixelPtr + @this.Step.X * k; for (; k < rightBound; k++) { for (var c = 0; c < channelsCount; c++) { outPixelPtr[c] += *kernelPtr * windowPtr[c]; } kernelPtr++; windowPtr += @this.Step.X; } for (; k <= rightOffset; k++) { for (var c = 0; c < channelsCount; c++) { outPixelPtr[c] += *kernelPtr * windowPtr[c]; } kernelPtr++; } inPixelPtr += @this.Step.X; outPixelPtr += answer.Step.X; } inPtr += @this.Step.Y; outPtr += answer.Step.Y; } } } return(answer); }
public ImageFloat prepare() { ImageFloat ret = new ImageFloat(yarpPINVOKE.BufferedPortImageFloat_prepare(swigCPtr), false); return ret; }
public new void onRead(ImageFloat datum) { yarpPINVOKE.BufferedPortImageFloat_onRead(swigCPtr, ImageFloat.getCPtr(datum)); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); }
public new bool write(Bottle data1, ImageFloat data2) { bool ret = yarpPINVOKE.Port_write__SWIG_9(swigCPtr, Bottle.getCPtr(data1), ImageFloat.getCPtr(data2)); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public new bool write(ImageFloat data) { bool ret = yarpPINVOKE.Port_write__SWIG_7(swigCPtr, ImageFloat.getCPtr(data)); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static new bool read(ImageFloat dest, string src) { bool ret = yarpPINVOKE.read__SWIG_4(ImageFloat.getCPtr(dest), src); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static new bool write(ImageFloat src, string dest) { bool ret = yarpPINVOKE.write__SWIG_4(ImageFloat.getCPtr(src), dest); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public ImageFloat prepare() { ImageFloat ret = new ImageFloat(yarpPINVOKE.BufferedPortImageFloat_prepare(swigCPtr), false); return(ret); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageFloat obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public new void onRead(ImageFloat datum, TypedReaderImageFloat reader) { yarpPINVOKE.TypedReaderCallbackImageFloat_onRead__SWIG_1(swigCPtr, ImageFloat.getCPtr(datum), TypedReaderImageFloat.getCPtr(reader)); if (yarpPINVOKE.SWIGPendingException.Pending) throw yarpPINVOKE.SWIGPendingException.Retrieve(); }
internal static HandleRef getCPtr(ImageFloat obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }