/** * Splits a ColorBitmap into an RGBBitmap struct containing the * individual color componenets. The original ColorBitmap is left unmodified. * * @param fromColors The bitmap to split into channels. * @param toRGB RGBBitmap struct containing the channels for the ColorBitmap. */ public static void colorBitmapToRGBBitmap(ref ColorBitmap fromColors, ref RGBBitmap toRGB) { int channelLength = fromColors.colors.Length; string logString = string.Format("Converting bitmap to RGB (length {0})", channelLength); OnionLogger.globalLog.PushInfoLayer(logString); float[] r = new float[channelLength]; float[] g = new float[channelLength]; float[] b = new float[channelLength]; for (int i = 0; i < channelLength; ++i) { Color colorTuple = fromColors.colors[i]; r[i] = colorTuple.r; g[i] = colorTuple.g; b[i] = colorTuple.b; } RGBChannels rgb = new RGBChannels(); rgb.r = r; rgb.g = g; rgb.b = b; toRGB.rgb = rgb; toRGB.width = fromColors.width; toRGB.height = fromColors.height; OnionLogger.globalLog.PopInfoLayer(); }
private void AllFramesReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame == null) { return; } colorFrame.CopyPixelDataTo(ColorPixels); ColorBitmap.WritePixels( new Int32Rect(0, 0, ColorBitmap.PixelWidth, ColorBitmap.PixelHeight), ColorPixels, ColorBitmap.PixelWidth * sizeof(int), 0); DetectMotion(); } if (FrameUpdated != null) { FrameUpdated(this, new EventArgs()); } }
public virtual void RenderColorImageInBitmap(ref ColorBitmap bitmap) { OnionLogger.globalLog.PushInfoLayer("BModeOutputImageDecoder"); // Acquire data from the probe output. UltrasoundScanData data = probeOutput.SendScanData(); // Render the data to a bitmap OnionLogger.globalLog.PushInfoLayer("Rendering UltrasoundData to bitmap"); foreach (UltrasoundScanline scanline in data) { foreach (UltrasoundPoint point in scanline) { int index = MapScanningPlaneToPixelCoordinate(bitmap.height, bitmap.width, point.GetProjectedLocation(), data.GetProbeConfig()); DrawPoint(point, index, ref bitmap); } } OnionLogger.globalLog.PopInfoLayer(); // Apply post-processing effects OnionLogger.globalLog.PushInfoLayer("Post-processing"); foreach (IImagePostProcessor effect in imageEffects) { effect.ProcessBitmap(ref bitmap); } OnionLogger.globalLog.PopInfoLayer(); OnionLogger.globalLog.PopInfoLayer(); }
//Draw Color Frame public static void DrawColorFrame(TColorFrame colorData) { ColorBitmap.WritePixels( new Int32Rect(0, 0, ColorBitmap.PixelWidth, ColorBitmap.PixelHeight), colorData.ColorData, ColorBitmap.PixelWidth * sizeof(int), 0); }
/** * Joins an RGBBitmap struct containing individual color components into a single * bitmap (array of UnityEngine.Color). The RGBBitmap is left unchanged. * * @param fromRGB The RGB data to join into a ColorBitmap. * @param toColors A ColorBitmap equivalent to the rgb data. */ public static void RGBBitmapToColorBitmap(ref RGBBitmap fromRGB, ref ColorBitmap toColors) { int channelLength = fromRGB.rgb.r.Length; string logString = string.Format("Converting RGBBitmap to ColorBitmap (length {0})", channelLength); OnionLogger.globalLog.PushInfoLayer(logString); toColors.colors = new Color[channelLength]; toColors.width = fromRGB.width; toColors.height = fromRGB.height; for (int i = 0; i < channelLength; ++i) { toColors.colors[i] = new Color(fromRGB.rgb.r[i], fromRGB.rgb.g[i], fromRGB.rgb.b[i]); } OnionLogger.globalLog.PopInfoLayer(); }
public void RenderColorImageInBitmap(ref ColorBitmap bitmap) { OnionLogger.globalLog.PushInfoLayer("TestImageSource"); long totalPixels = bitmap.colors.Length; for (int index = 0; index < totalPixels; ++index) { Color c = bars[(index / 5) % bars.Length]; bitmap.colors[index] = c; } OnionLogger.globalLog.PushInfoLayer("Post-processing"); foreach (IImagePostProcessor effect in imageEffects) { effect.ProcessBitmap(ref bitmap); } OnionLogger.globalLog.PopInfoLayer(); OnionLogger.globalLog.PopInfoLayer(); }
public void RenderNextFrameToTexture(ref Texture2D texture) { OnionLogger.globalLog.PushInfoLayer("TextureSource"); OnionLogger.globalLog.PushInfoLayer("Allocating ColorBitmap"); ColorBitmap colorBitmap = new ColorBitmap(); colorBitmap.width = texture.width; colorBitmap.height = texture.height; colorBitmap.colors = new Color[colorBitmap.width * colorBitmap.height]; OnionLogger.globalLog.PopInfoLayer(); imageSource.RenderColorImageInBitmap(ref colorBitmap); OnionLogger.globalLog.PushInfoLayer("Applying Bitmap to texture"); texture.SetPixels(colorBitmap.colors); texture.Apply(); OnionLogger.globalLog.PopInfoLayer(); OnionLogger.globalLog.PopInfoLayer(); }
/** * Applies gaussian blur effect to a grayscale bitmap. * @param colorBitmap the image to be processed. */ public void ProcessBitmap(ref ColorBitmap colorBitmap) { OnionLogger.globalLog.PushInfoLayer("Performing GrayscaleGaussianBlur on bitmap."); RGBBitmap rgbBitmap = new RGBBitmap(); ColorUtils.colorBitmapToRGBBitmap(ref colorBitmap, ref rgbBitmap); /* Since we are assuming the image is grayscale, we can apply the blur to just one * channel. We arbitrarily choose the red channel. */ MonochromeBitmap blurR = ColorUtils.redBitmapFromRGBBitmap(ref rgbBitmap); // temporarily hard-coded int numberOfCoefficients = 5; this.coefficients = ApproximateGaussianCoefficients(numberOfCoefficients); OnionLogger.globalLog.PushInfoLayer("Blurring rows"); ExecuteHorizontalBlur(ref blurR); ColorUtils.Transpose(ref blurR); /* transpose to set up for blurring columns */ OnionLogger.globalLog.PopInfoLayer(); // Since we transposed the image, we can re-use the horizontal blur operation to blur the columns. OnionLogger.globalLog.PushInfoLayer("Blurring columns"); ExecuteHorizontalBlur(ref blurR); ColorUtils.Transpose(ref blurR); /* reset the image to original orientation */ OnionLogger.globalLog.PopInfoLayer(); // Since we assumed that we are using a grayscale image, the Blue and Green channels can be copied from // the red channel. rgbBitmap.rgb.r = blurR.channel; rgbBitmap.rgb.b = blurR.channel; rgbBitmap.rgb.g = blurR.channel; ColorUtils.RGBBitmapToColorBitmap(ref rgbBitmap, ref colorBitmap); OnionLogger.globalLog.PopInfoLayer(); }
/** * Draw a single UltrasoundPoint into a color buffer. * @param point The UltrasoundPoint data to draw. * @param index The index in the buffer at which to place the pixel. * @param bitmap The bitmap into which to draw the pixel. */ protected virtual void DrawPoint(UltrasoundPoint point, int index, ref ColorBitmap bitmap) { long bufferSize = bitmap.colors.Length; #if UNITY_EDITOR UltrasoundDebug.Assert(index < bufferSize && index >= 0, string.Format("{0} should be in the interval[0, {1})", index, bufferSize), this); UltrasoundDebug.Assert(point.GetBrightness() >= 0f && point.GetBrightness() <= 1f, string.Format("Pixel brightness {0} should be in the interval [0,1]", point.GetBrightness()), this); #endif if (index >= bufferSize || index < 0) { return; } Color pointColor = drawColor; // minimum pixel brightness of 0.1f pointColor *= Mathf.Max(0.1f, point.GetBrightness()); bitmap.colors[index] = pointColor; }
/** * Invert the colors of a bitmap. * * @param colorBitmap The ColorBitmap to invert. */ public void ProcessBitmap(ref ColorBitmap colorBitmap) { OnionLogger.globalLog.PushInfoLayer("Inverting bitmap"); RGBBitmap rgbBitmap = new RGBBitmap(); ColorUtils.colorBitmapToRGBBitmap(ref colorBitmap, ref rgbBitmap); MonochromeBitmap invertedr = ColorUtils.redBitmapFromRGBBitmap(ref rgbBitmap); MonochromeBitmap invertedg = ColorUtils.greenBitmapFromRGBBitmap(ref rgbBitmap); MonochromeBitmap invertedb = ColorUtils.blueBitmapFromRGBBitmap(ref rgbBitmap); // We'll run a thread for each color channel. int numberOfThreads = 3; ManualResetEvent[] threadsDone = new ManualResetEvent[numberOfThreads]; ColorInvertThread[] threads = new ColorInvertThread[numberOfThreads]; for (int i = 0; i < numberOfThreads; ++i) { threadsDone[i] = new ManualResetEvent(false); threads[i] = new ColorInvertThread(threadsDone[i]); } ThreadPool.QueueUserWorkItem(new WaitCallback(threads[0].ThreadedProcessChannel), invertedr); ThreadPool.QueueUserWorkItem(new WaitCallback(threads[1].ThreadedProcessChannel), invertedg); ThreadPool.QueueUserWorkItem(new WaitCallback(threads[2].ThreadedProcessChannel), invertedb); WaitHandle.WaitAll(threadsDone); // Done with parallel section. rgbBitmap.rgb.r = invertedr.channel; rgbBitmap.rgb.g = invertedg.channel; rgbBitmap.rgb.b = invertedb.channel; ColorUtils.RGBBitmapToColorBitmap(ref rgbBitmap, ref colorBitmap); OnionLogger.globalLog.PopInfoLayer(); }