/// <summary> /// Apply filter. /// </summary> /// <param name="bmData">Bitmap data</param> public unsafe void Apply(BitmapData bmData) { byte *p = (byte *)bmData.Scan0.ToPointer(); int width = bmData.Width, height = bmData.Height, stride = bmData.Stride; float z = 1 - s; Parallel.For(0, height, y => { YUV nYUV, iYUV; RGB rgb; int nR, nG, nB, iR, iG, iB; int x, ystride, k, luma; ystride = y * stride; for (x = 0; x < width; x++) { k = ystride + x * 4; iR = p[k + 2]; iG = p[k + 1]; iB = p[k]; luma = RGB.HDTV(iR, iG, iB); nYUV = YUV.FromRGB(luma, luma, luma); iYUV = YUV.FromRGB(color.R, color.G, color.B); rgb = AddColor(nYUV, iYUV).ToRGB; nR = rgb.Red; nG = rgb.Green; nB = rgb.Blue; p[k + 2] = Maths.Byte(nR * s + iR * z); p[k + 1] = Maths.Byte(nG * s + iG * z); p[k] = Maths.Byte(nB * s + iB * z); } } ); return; }
private void SetYUVLabels() { YUV yuvColor = new YUV(current_color); label_YUV_Y.Text = "Y: " + yuvColor.Y.ToString("0.000"); label_YUV_U.Text = "U: " + yuvColor.U.ToString("0.000"); label_YUV_V.Text = "V: " + yuvColor.V.ToString("0.000"); }
public RGB Convert(YUV input) { var Y = input.Y; var u = input.U; var v = input.V; var R = Y + 1.140 * v; var G = Y - 0.395 * u - 0.581 * v; var B = Y + 2.032 * u; return(new RGB(new Vector(R, G, B).Coerce(0, 1))); }
/// <summary> /// Converts RGB to YUV. /// </summary> /// <param name="red">Red must be in [0, 255].</param> /// <param name="green">Green must be in [0, 255].</param> /// <param name="blue">Blue must be in [0, 255].</param> public static YUV RGBtoYUV(double red, double green, double blue) { YUV yuv = new YUV(); // normalizes red, green, blue values double r = (double)red / 255.0; double g = (double)green / 255.0; double b = (double)blue / 255.0; yuv.Y = 0.299 * r + 0.587 * g + 0.114 * b; yuv.U = -0.14713 * r - 0.28886 * g + 0.436 * b; yuv.V = 0.615 * r - 0.51499 * g - 0.10001 * b; return(yuv); }
/// <summary> /// Converts RGB to YUV. /// </summary> /// <param name="red">red must be in [0, 255].</param> /// <param name="green">green must be in [0, 255].</param> /// <param name="blue">blue must be in [0, 255].</param> public static YUV RGBtoYUV(int red, int green, int blue) { YUV yuv = new YUV(); // normalizes red/green/blue values double nRed = red / 255.0; double nGreen = green / 255.0; double nBlue = blue / 255.0; // converts yuv.Y = 0.299 * nRed + 0.587 * nGreen + 0.114 * nBlue; yuv.U = -0.1471376975169300226 * nRed - 0.2888623024830699774 * nGreen + 0.436 * nBlue; yuv.V = 0.615 * nRed - 0.5149857346647646220 * nGreen - 0.1000142653352353780 * nBlue; return(yuv); }
static void Main(string[] args) { int red = Convert.ToInt32(Console.ReadLine()); int green = Convert.ToInt32(Console.ReadLine()); int blue = Convert.ToInt32(Console.ReadLine()); RGB renk; renk.R = red; renk.G = green; renk.B = blue; YUV renk_YUV = convert(renk); Console.WriteLine(renk_YUV.Y); Console.WriteLine(renk_YUV.U); Console.WriteLine(renk_YUV.V); Console.ReadLine(); }
private void CreateYUVLayout() { Hide4Elements(); YUV YUV_color = new YUV(current_color); label1.Text = "Y"; label2.Text = "U"; label3.Text = "V"; setting_tb_and_nup = true; numericUpDown1.Maximum = 1; numericUpDown2.Maximum = (decimal)YUV.U_max; numericUpDown3.Maximum = (decimal)YUV.V_max; numericUpDown1.Minimum = 0; numericUpDown2.Minimum = (decimal) - YUV.U_max; numericUpDown3.Minimum = (decimal) - YUV.V_max; numericUpDown1.Increment = new decimal(0.01); numericUpDown2.Increment = new decimal(0.01); numericUpDown3.Increment = new decimal(0.01); trackBar1.Value = (int)(YUV_color.Y * 255); trackBar2.Value = (int)((YUV_color.U + YUV.U_max) / (2 * YUV.U_max) * 255); trackBar3.Value = (int)((YUV_color.V + YUV.V_max) / (2 * YUV.V_max) * 255); numericUpDown1.Value = (decimal)YUV_color.Y; numericUpDown2.Value = (decimal)YUV_color.U; numericUpDown3.Value = (decimal)YUV_color.V; setting_tb_and_nup = false; SetDecimalPlaces(3); SetYUVLabels(); }
/// <summary> /// Converts RGB to YUV. /// </summary> /// <param name="red">Red must be in [0, 255].</param> /// <param name="green">Green must be in [0, 255].</param> /// <param name="blue">Blue must be in [0, 255].</param> public static YUV RGBtoYUV(int red, int green, int blue) { YUV yuv = new YUV(); // normalizes red, green, blue values double r = (double)red / 255.0; double g = (double)green / 255.0; double b = (double)blue / 255.0; yuv.Y = 0.299 * r + 0.587 * g + 0.114 * b; yuv.U = -0.14713 * r - 0.28886 * g + 0.436 * b; yuv.V = 0.615 * r - 0.51499 * g - 0.10001 * b; return yuv; }
/// <summary> /// Converts YUV to a .net Color. /// </summary> public static Color YUVtoColor(YUV yuv) { RGB rgb = YUVtoRGB(yuv); return(Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue)); }
/// <summary> /// Converts YUV to RGB. /// </summary> public static RGB YUVtoRGB(YUV yuv) { return(YUVtoRGB(yuv.Y, yuv.U, yuv.V)); }
/// <summary> /// Blend two colors in YUV space. /// </summary> /// <param name="yuv1">First color</param> /// <param name="yuv2">Second color</param> /// <returns>YUV</returns> public static YUV AddColor(YUV yuv1, YUV yuv2) { return(new YUV(yuv1.Y, yuv1.U + yuv2.U, yuv1.V + yuv2.V)); }
public bool Equals(YUV yuv) { return((this.Y == yuv.Y) && (this.U == yuv.U) && (this.V == yuv.V)); }