Exemplo n.º 1
0
        /// <summary>
        /// Gets the complementary color of the one given.
        /// </summary>
        /// <param name="source">The color to find the complement of.</param>
        /// <returns>The complement to the input color.</returns>
        public static Color GetComplementaryColor(Color source)
        {
            var inputColor = source;
            // If RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side,
            // decrease the blue by 50% (eventually it will increase in conversion below), if RBB values are on darker
            // side, decrease yellow by about 50% (it will increase in conversion)
            var avgColorValue = (byte)((source.R + source.G + source.B) / 3);
            var diffR = Math.Abs(source.R - avgColorValue);
            var diffG = Math.Abs(source.G - avgColorValue);
            var diffB = Math.Abs(source.B - avgColorValue);
            if (diffR < 20 && diffG < 20 && diffB < 20) //The color is a shade of gray
            {
                if (avgColorValue < 123) //color is dark
                {
                    inputColor.B = 220;
                    inputColor.G = 230;
                    inputColor.R = 50;
                }
                else
                {
                    inputColor.R = 255;
                    inputColor.G = 255;
                    inputColor.B = 50;
                }
            }

            var rgb = new Rgb { R = inputColor.R, G = inputColor.G, B = inputColor.B };
            var hsb = ConvertToHsb(rgb);
            hsb.H = hsb.H < 180 ? hsb.H + 180 : hsb.H - 180;
            //hsb.B = isColorDark ? 240 : 50; //Added to create dark on light, and light on dark
            rgb = ConvertToRgb(hsb);
            return new Color { A = 255, R = (byte)rgb.R, G = (byte)rgb.G, B = (byte)rgb.B };
        }
Exemplo n.º 2
0
        public void WhiteXamarinToRgb()
        {
            var knownColor    = Xamarin.Forms.Color.White;
            var expectedColor = new Rgb {
                R = 255, G = 255, B = 255,
            };

            var conv = knownColor.To <Rgb>();

            (conv.R - expectedColor.R < diff).IsTrue();
            (conv.G - expectedColor.G < diff).IsTrue();
            (conv.B - expectedColor.B < diff).IsTrue();
        }
Exemplo n.º 3
0
        public void GoldenrodXamarinToRgb()
        {
            var knownColor    = Xamarin.Forms.Color.FromRgb(218, 165, 32);
            var expectedColor = new Rgb {
                R = 218, G = 165, B = 32,
            };

            var conv = knownColor.To <Rgb>();

            (conv.R - expectedColor.R < diff).IsTrue();
            (conv.G - expectedColor.G < diff).IsTrue();
            (conv.B - expectedColor.B < diff).IsTrue();
        }
Exemplo n.º 4
0
        public void MaroonXamarinToRgb()
        {
            var knownColor    = Xamarin.Forms.Color.Maroon;
            var expectedColor = new Rgb {
                R = 128, G = 0, B = 0
            };

            var conv = knownColor.To <Rgb>();

            (conv.R - expectedColor.R < diff).IsTrue();
            (conv.G - expectedColor.G < diff).IsTrue();
            (conv.B - expectedColor.B < diff).IsTrue();
        }
Exemplo n.º 5
0
        public void Convert_Rgb_To_Hsl(float r, float g, float b, float h, float s, float l)
        {
            // Arrange
            Rgb input = new Rgb(r, g, b);

            // Act
            Hsl output = Converter.ToHsl(input);

            // Assert
            Assert.Equal(h, output.H, FloatRoundingComparer);
            Assert.Equal(s, output.S, FloatRoundingComparer);
            Assert.Equal(l, output.L, FloatRoundingComparer);
        }
Exemplo n.º 6
0
        public static void FromHex_GivenIncorrectLengthString_ThrowsArgException()
        {
            Assert.Multiple(() =>
            {
                // > 3 but < 6
                Assert.Throws <ArgumentException>(() => Rgb.FromHex("1234"));
                Assert.Throws <ArgumentException>(() => Rgb.FromHex("#1234"));

                // >6
                Assert.Throws <ArgumentException>(() => Rgb.FromHex("1234567"));
                Assert.Throws <ArgumentException>(() => Rgb.FromHex("#1234567"));
            });
        }
Exemplo n.º 7
0
        public List <double> CalculateRegionsDeltaEList(Bitmap image, List <IntPoint2D> listOfPoints, IntPoint2D originPoint)
        {
            var originPixelColor = image.GetPixel(originPoint.X, originPoint.Y);
            var originPixelRgb   = new Rgb {
                R = originPixelColor.R, B = originPixelColor.B, G = originPixelColor.G
            };

            return(listOfPoints.Select(point => image.GetPixel(point.X, point.Y))
                   .Select(imagePixelColor => new Rgb {
                R = imagePixelColor.R, B = imagePixelColor.B, G = imagePixelColor.G
            })
                   .Select(imageRgb => imageRgb.Compare(originPixelRgb, new CieDe2000Comparison())).ToList());
        }
        public void Convert_Rgb_To_Hsv(float r, float g, float b, float h, float s, float v)
        {
            // Arrange
            var input = new Rgb(r, g, b);

            // Act
            Hsv output = Converter.ToHsv(input);

            // Assert
            Assert.Equal(h, output.H, FloatRoundingComparer);
            Assert.Equal(s, output.S, FloatRoundingComparer);
            Assert.Equal(v, output.V, FloatRoundingComparer);
        }
Exemplo n.º 9
0
        public void Convert_Rgb_To_YCbCr(float r, float g, float b, float y, float cb, float cr)
        {
            // Arrange
            Rgb input = new Rgb(r, g, b);

            // Act
            YCbCr output = Converter.ToYCbCr(input);

            // Assert
            Assert.Equal(y, output.Y, FloatRoundingComparer);
            Assert.Equal(cb, output.Cb, FloatRoundingComparer);
            Assert.Equal(cr, output.Cr, FloatRoundingComparer);
        }
Exemplo n.º 10
0
        public static CIELabColor RgbColorToCIELabColor(Color rgbColor)
        {
            var labColor = new Rgb {
                R = rgbColor.R, B = rgbColor.B, G = rgbColor.G
            }.To <Lab>();

            return(new CIELabColor
            {
                L = LDoubleToUshort(labColor.L),
                A = ABDoubleToUShort(labColor.A),
                B = ABDoubleToUShort(labColor.B)
            });
        }
Exemplo n.º 11
0
        public async Task FadeIn()
        {
            var monitor = GetMonitor();

            monitor.Reading = 100;

            var filter = new PowerFilter(new FakeContainer(), monitor);
            await filter.PreApply(0);

            var color = await filter.ApplyFilter(Rgb.FromHex("FFFFFF"));

            Assert.AreEqual(Rgb.FromHex("000000"), color);
        }
Exemplo n.º 12
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            RGB = new Rgb(0, 0, 0);
            HSV = new Hsv(0, 0, 0);
            CMY = new Cmyk(0, 0, 0, 0);

            Change_RGB();
            Change_HSV();
            Change_CMYK();
        }
 public void DrawVisualization(SimulationStructure structure, Image <Rgb, byte> image)
 {
     for (var i = 0; i < image.Size.Height; i++)
     {
         var w = ((int)(((double)i) / ((double)image.Size.Height) * image.Size.Width));
         if (w == image.Size.Width)
         {
             w--;
         }
         var wComp = image.Size.Width - 1 - w;
         image[i, w]     = new Rgb(Color.Red);
         image[i, wComp] = new Rgb(Color.Red);
     }
 }
        public void Convert_YCbCr_To_Rgb(float y, float cb, float cr, float r, float g, float b)
        {
            // Arrange
            var input = new YCbCr(y, cb, cr);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace, ApproximateComparer);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
Exemplo n.º 15
0
        public Image <Rgb, byte> DrawLines(Rgb color, bool append = false)
        {
            if (!append)
            {
                figure[2] = raw.CopyBlank();
            }
            lines = lines.Where(s_isValid()).ToArray();
            foreach (LineSegment2D line in lines)
            {
                figure[2].Draw(line, color, 1);
            }

            return(figure[2]);
        }
Exemplo n.º 16
0
        public void Convert_Hsl_To_Rgb(float h, float s, float l, float r, float g, float b)
        {
            // Arrange
            Hsl input = new Hsl(h, s, l);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Generates an AnnotatedFrame with randomly filled Data and the given Macroblock decisions.
        /// </summary>
        /// <returns> An annotated Frame with random Data and the given Macroblock decisions.</returns>
        public static AnnotatedFrame GenerateAnnFrame(MacroblockDecision[,] decisions)
        {
            var testSize = new YuvKA.VideoModel.Size(8, 8);
            var output   = new AnnotatedFrame(testSize, decisions);

            for (int x = 0; x < testSize.Width; x++)
            {
                for (int y = 0; y < testSize.Height; y++)
                {
                    output[x, y] = new Rgb((byte)(x + y), (byte)(x + y), (byte)(x + y));
                }
            }
            return(output);
        }
Exemplo n.º 18
0
        public void Convert_Rgb_To_Cmyk(float r, float g, float b, float c, float m, float y, float k)
        {
            // Arrange
            Rgb input = new Rgb(r, g, b);

            // Act
            Cmyk output = Converter.ToCmyk(input);

            // Assert
            Assert.Equal(c, output.C, FloatRoundingComparer);
            Assert.Equal(m, output.M, FloatRoundingComparer);
            Assert.Equal(y, output.Y, FloatRoundingComparer);
            Assert.Equal(k, output.K, FloatRoundingComparer);
        }
Exemplo n.º 19
0
        public void SetDefaultCubeHelix()
        {
            int maxPalletteIndex = maxPalletteSize - 1;
            var pallette         = new Color[maxPalletteSize];

            for (int c = 0; c < maxPalletteSize; c++)
            {
                double value     = c / (double)maxPalletteIndex;
                Rgb    rgbColour = this.GetColor(value);
                pallette[c] = Color.FromArgb((int)rgbColour.R, (int)rgbColour.G, (int)rgbColour.B);
            }

            this.ColourPallette = pallette;
        }
Exemplo n.º 20
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            string    strHex  = lblSelected.Text;
            ColorCode colorcd = new ColorCode();

            foreach (ImageColorInfo info in qList)
            {
                if (info.HEXValue.Equals(strHex))
                {
                    qList.Remove(info);
                    break;
                }
            }
            _point    = new Xamarin.Forms.Point(0.0, 0.0);
            lastXMove = lastXMoveBak;
            lastYMove = lastYMoveBak;
            if (qList.Count > 0)
            {
                string hex = qList[qList.Count - 1].HEXValue;
                btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(hex);
                lblSelected.Text         = hex;
                lblHex.Text = hex;
                Rgb rgb = colorcd.getRgb(hex);
                lblRgb.Text     = colorcd.getRgbString(rgb);
                lblHsl.Text     = colorcd.getHslString(rgb);
                lblHsv.Text     = colorcd.getHsvString(rgb);
                lblCmyk.Text    = colorcd.getCmykString(rgb);
                lblLab.Text     = colorcd.getLabString(rgb);
                lblMunsell.Text = colorcd.getMunsellString(rgb);
                lblPccs.Text    = colorcd.getPCCSTone(rgb);
                lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);
            }
            else
            {
                btnColor.BackgroundColor = Xamarin.Forms.Color.White;
                lblSelected.Text         = string.Empty;
                lblHex.Text     = string.Empty;
                lblRgb.Text     = string.Empty;
                lblHsl.Text     = string.Empty;
                lblHsv.Text     = string.Empty;
                lblCmyk.Text    = string.Empty;
                lblLab.Text     = string.Empty;
                lblMunsell.Text = string.Empty;
                lblPccs.Text    = string.Empty;
                lblJis.Text     = string.Empty;
            }

            // カンバス更新
            canvasView.InvalidateSurface();
        }
Exemplo n.º 21
0
        private void autoBtn_Click(object sender, EventArgs e)
        {
            var accentColor = WindowCustomizationUtility.GetActiveAccentColor();

            var rgb = new Rgb(accentColor.R, accentColor.G, accentColor.B);
            var hsl = rgb.To <Hsl>();

            hsl.L *= 1.65;
            rgb    = hsl.To <Rgb>();

            Red   = (int)rgb.R;
            Green = (int)rgb.G;
            Blue  = (int)rgb.B;
        }
Exemplo n.º 22
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            if (op.ShowDialog() == DialogResult.OK)
            {
                Mat img = new Mat(op.FileName, Emgu.CV.CvEnum.LoadImageType.AnyColor);
                imageBox1.Image = img;
            }
            //點,线,矩形,園,橢圓
            MCvPoint3D32f  mCvPoint3D32F  = new MCvPoint3D32f(0, 0, 0);
            PointF         x              = new PointF(0, 0);
            PointF         y              = new PointF(1, 1);
            LineSegment2DF lineSegment2DF = new LineSegment2DF(x, y);

            //顏色
            Rgb rgb = new Rgb(Color.Red);
            Rgb red = new Rgb(255, 0, 0);
            //類型轉換
            Bitmap            bitmap = new Bitmap(640, 480);
            Image <Bgr, byte> image  = new Image <Bgr, byte>(640, 480);
            Mat mat = new Mat();

            op = new OpenFileDialog();
            if (op.ShowDialog() == DialogResult.OK)
            {
                Bitmap            bitmap_new = new Bitmap(op.FileName);
                Image <Bgr, byte> image_new  = new Image <Bgr, byte>(op.FileName);
                Mat mat_new = new Mat(op.FileName, Emgu.CV.CvEnum.LoadImageType.AnyColor);

                pictureBox1.Image = bitmap_new;
                pictureBox1.Image = image_new.ToBitmap();
                //pictureBox1.Image = mat_new.Bitmap;
                pictureBox1.Image = mat_new.ToImage <Bgr, byte>().Bitmap;

                imageBox1.Image = new Image <Bgr, byte>(bitmap_new);
                imageBox1.Image = image_new;
                imageBox1.Image = mat_new;
            }
            Image <Bgr, byte> img          = new Image <Bgr, byte>(200, 200, new Bgr(255, 255, 255));
            Rectangle         rectangle    = new Rectangle(new Point(80, 80), new Size(40, 40));
            CircleF           circleF      = new CircleF(new PointF(100, 100), 40);
            string            str          = "I LOVE EmguCV";
            Point             str_location = new Point(0, 30);

            img.Draw(rectangle, new Bgr(0, 255, 0), 2);
            img.Draw(circleF, new Bgr(0, 0, 255), 3);
            img.Draw(str, str_location, Emgu.CV.CvEnum.FontFace.HersheyComplexSmall, 1, new Bgr(0, 255, 0), 3);
            imageBox1.Image = img;
        }
Exemplo n.º 23
0
        public void Convert_Cmyk_To_Rgb(float c, float m, float y, float k, float r, float g, float b)
        {
            // Arrange
            Cmyk input = new Cmyk(c, m, y, k);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
Exemplo n.º 24
0
        public void ConsolePalette()
        {
            var ConsolePalette = new Palette <Rgb>()
            {
                new Rgb(0x00, 0x00, 0x00),
                new Rgb(0x80, 0x00, 0x00),
                new Rgb(0x00, 0x80, 0x00),
                new Rgb(0x80, 0x80, 0x00),
                new Rgb(0x00, 0x00, 0x80),
                new Rgb(0x80, 0x00, 0x80),
                new Rgb(0x00, 0x80, 0x80),
                new Rgb(0xc0, 0xc0, 0xc0),
                new Rgb(0x80, 0x80, 0x80),
                new Rgb(0xff, 0x00, 0x00),
                new Rgb(0x00, 0xff, 0x00),
                new Rgb(0xff, 0xff, 0x00),
                new Rgb(0x00, 0x00, 0xff),
                new Rgb(0xff, 0x00, 0xff),
                new Rgb(0x00, 0xff, 0xff),
                new Rgb(0xff, 0xff, 0xff)
            };
            Rgb testColor;

            Palette <Rgb> .FindResult <Rgb> testResult;

            // Going to run a test at each end of the spectrum
            testColor  = new Rgb(0x70, 0x20, 0x20);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(1, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);

            testColor  = new Rgb(0x20, 0x90, 0x20);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(2, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);

            testColor  = new Rgb(0x90, 0x70, 0x20);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(3, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);

            testColor  = new Rgb(0x20, 0x20, 0x87);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(4, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);

            testColor  = new Rgb(0x90, 0x00, 0x87);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(5, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);

            testColor  = new Rgb(0x20, 0x90, 0x87);
            testResult = ConsolePalette.FindClosestColor <Rgb>(testColor);
            Assert.AreEqual(6, testResult.Index, testColor.ToString() + " != " + testResult.ToString() + " => " + testResult.Distance);
        }
Exemplo n.º 25
0
        public void RgbEquality()
        {
            var x = default(Rgb);
            var y = new Rgb(Vector3.One);

            Assert.True(default(Rgb) == default(Rgb));
            Assert.False(default(Rgb) != default(Rgb));
            Assert.Equal(default(Rgb), default(Rgb));
            Assert.Equal(new Rgb(1, 0, 1), new Rgb(1, 0, 1));
            Assert.Equal(new Rgb(Vector3.One), new Rgb(Vector3.One));
            Assert.False(x.Equals(y));
            Assert.False(x.Equals((object)y));
            Assert.False(x.GetHashCode().Equals(y.GetHashCode()));
        }
Exemplo n.º 26
0
        private static void ValidateYCbCr(JpegColorConverter.ComponentValues values, Vector4[] result, int i)
        {
            float y     = values.Component0[i];
            float cb    = values.Component1[i];
            float cr    = values.Component2[i];
            var   ycbcr = new YCbCr(y, cb, cr);

            Vector4 rgba     = result[i];
            var     actual   = new Rgb(rgba.X, rgba.Y, rgba.Z);
            var     expected = ColorSpaceConverter.ToRgb(ycbcr);

            Assert.True(actual.AlmostEquals(expected, Precision), $"{actual} != {expected}");
            Assert.Equal(1, rgba.W);
        }
Exemplo n.º 27
0
        private void SetBlackFrame(Size size)
        {
            Frame blackFrame = new Frame(size);
            Rgb   black      = new Rgb(0, 0, 0);

            for (int x = 0; x < size.Width; x++)
            {
                for (int y = 0; y < size.Height; y++)
                {
                    blackFrame[x, y] = black;
                }
            }
            Data = blackFrame;
        }
Exemplo n.º 28
0
        public void Convert_Hsv_To_Rgb(float h, float s, float v, float r, float g, float b)
        {
            // Arrange
            var input = new Hsv(h, s, v);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace, ApproximateComparer);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
Exemplo n.º 29
0
        private Frame ProcessCoherentNoise(int tick)
        {
            Random rnd = new Random(seed % (tick == 0 ? 1 : tick));

            for (int y = 0; y < Size.Height; ++y)
            {
                for (int x = 0; x < Size.Width; ++x)
                {
                    byte color = (byte)rnd.Next(256);
                    outputFrame[x, y] = new Rgb(color, color, color);
                }
            }
            return(outputFrame);
        }
Exemplo n.º 30
0
        private static void LABtoRGB(double l, double a, double labb, ref byte r, ref byte g, ref byte b)
        {
            Lab myLAB = new Lab
            {
                L = l,
                A = a,
                B = labb
            };

            Rgb myRGB = myLAB.To <Rgb>();

            r = (byte)myRGB.R;
            g = (byte)myRGB.G;
            b = (byte)myRGB.B;
        }
            internal static void ToColorSpace(Rgb color, Lab item)
            {
                var xyz = new Xyz();

                xyz.Initialize(color);

                var white = XyzConverter.WhiteReference;
                var x     = PivotXyz(xyz.X / white.X);
                var y     = PivotXyz(xyz.Y / white.Y);
                var z     = PivotXyz(xyz.Z / white.Z);

                item.L = Math.Max(0, 116 * y - 16);
                item.A = 500 * (x - y);
                item.B = 200 * (y - z);
            }
        //BindingSource bindingSource1 = new BindingSource();
        public MainWindow()
        {
            InitializeComponent();

            Rgb rgb = new Rgb();
            rgb.R = 100;
            rgb.G = 20;
            rgb.B = 30;

            Binding bindingR = new Binding();
            bindingR.Source = rgb;
            bindingR.Mode = BindingMode.TwoWay;
            bindingR.Path = new PropertyPath("R");
            this.slider1.SetBinding(Slider.ValueProperty, bindingR);

            // http://point56.blogspot.jp/2009/01/wpfslidertextbox.html
            // http://main.tinyjoker.net/Tech/CSharp/WPF/TextBox%A4%CE%C6%FE%CE%CF%A4%F2%A4%B9%A4%B0%A4%CB%A5%D0%A5%A4%A5%F3%A5%C7%A5%A3%A5%F3%A5%B0%A5%BD%A1%BC%A5%B9%A4%CB%C8%BF%B1%C7%A4%B9%A4%EB.html
            Binding bindingSlider1 = new Binding();
            bindingSlider1.ElementName = "slider1";
            bindingSlider1.Path = new PropertyPath("Value");
            bindingSlider1.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            this.textBox1.SetBinding(TextBox.TextProperty, bindingSlider1);
            // https://code.msdn.microsoft.com/windowsdesktop/XAML-WPF-IME-Windows-WPF-9ef457d7

            Binding bindingG = new Binding();
            bindingG.Source = rgb;
            bindingG.Mode = BindingMode.TwoWay;
            bindingG.Path = new PropertyPath("G");
            this.slider2.SetBinding(Slider.ValueProperty, bindingG);

            Binding bindingSlider2 = new Binding();
            bindingSlider2.ElementName = "slider2";
            bindingSlider2.Path = new PropertyPath("Value");
            bindingSlider2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            this.textBox2.SetBinding(TextBox.TextProperty, bindingSlider2);

            Binding bindingB = new Binding();
            bindingB.Source = rgb;
            bindingB.Mode = BindingMode.TwoWay;
            bindingB.Path = new PropertyPath("B");
            this.slider3.SetBinding(Slider.ValueProperty, bindingB);

            Binding bindingSlider3 = new Binding();
            bindingSlider3.ElementName = "slider3";
            bindingSlider3.Path = new PropertyPath("Value");
            bindingSlider3.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            this.textBox3.SetBinding(TextBox.TextProperty, bindingSlider3);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Convert the Yuy2 data to RGB data. The raw buffer stored by Kinect Studio is in the format of Yuy2. 
        /// </summary>
        /// <param name="y0"></param>
        /// <param name="u0"></param>
        /// <param name="y1"></param>
        /// <param name="v0"></param>
        /// <param name="rgb1"></param>
        /// <param name="rgb2"></param>
        private static void ConvertYuy2ToRgb(byte y0, byte u0, byte y1, byte v0, out Rgb rgb1, out Rgb rgb2)
        {
            rgb1 = new Rgb();
            rgb2 = new Rgb();

            int c = y0 - 16;
            int d = u0 - 128;
            int e = v0 - 128;

            rgb1.Red = ClipValue((298*c + 516*d + 128) >> 8); // blue
            rgb1.Green = ClipValue((298*c - 100*d - 208*e + 128) >> 8); // green
            rgb1.Blue = ClipValue((298*c + 409*e + 128) >> 8); // red
            c = y1 - 16;

            rgb2.Red = ClipValue((298*c + 516*d + 128) >> 8); // blue
            rgb2.Green = ClipValue((298*c - 100*d - 208*e + 128) >> 8); // green
            rgb2.Blue = ClipValue((298*c + 409*e + 128) >> 8); // red
        }
Exemplo n.º 34
0
        public static Rgb GetRgb(System.Drawing.Point point, byte[, ,] data)
        {
            Rgb rgb = new Rgb();

            rgb.Red = data[point.Y, point.X, 2];
            rgb.Green = data[point.Y, point.X, 1];
            rgb.Blue = data[point.Y, point.X, 0];

            return rgb;
        }
Exemplo n.º 35
0
        public static double ColorDistance(Rgb rgb1, Rgb rgb2)
        {
            var val = Math.Abs(rgb1.Red - rgb2.Red) + Math.Abs(rgb1.Green - rgb2.Green) + Math.Abs(rgb1.Blue - rgb2.Blue);

            return val;
        }
Exemplo n.º 36
0
 public void Initialize(Rgb color) {
     XyzConverter.ToColorSpace(color, this);
 }
Exemplo n.º 37
0
        /// <summary>
        /// Channel filter based on 2 images with RGB
        /// </summary>
        /// <param name="image1">The image1.</param>
        /// <param name="image2">The image2.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>Bitmap.</returns>
        public Bitmap Channel(Bitmap image1, Bitmap image2, Rgb filter)
        {
            try
            {
                int r = 0;
                int b = 0;
                int g = 0;

                BitmapData fileData = image1.LockBits(new Rectangle(0, 0, image1.Width, image1.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                int stride = fileData.Stride;

                BitmapData fileData1 = image2.LockBits(new Rectangle(0, 0, image2.Width, image2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                unsafe
                {
                    byte* ptr = (byte*)fileData.Scan0;
                    byte* ptr1 = (byte*)fileData1.Scan0;

                    int bytesPerPixel = 3;

                    int remain = stride - fileData.Width * bytesPerPixel;

                    for (int y = 0; y < fileData.Height; y++)
                    {
                        for (int x = 0; x < fileData.Width; x++)
                        {
                            switch (filter)
                            {
                                case Rgb.Blue:
                                    b = (int)ptr[1];
                                    if (b == 0)
                                    {
                                        b = (int)ptr1[0];
                                    }

                                    g = (int)ptr1[1];
                                    r = (int)ptr1[2];
                                    break;

                                case Rgb.Green:
                                    b = (int)ptr1[0];
                                    g = (int)ptr[0];
                                    if (g == 0)
                                    {
                                        g = (int)ptr1[1];
                                    }
                                    r = (int)ptr1[2];
                                    break;

                                case Rgb.Red:
                                    b = (int)ptr1[0];
                                    g = (int)ptr1[1];
                                    r = (int)ptr[0];
                                    if (r == 0)
                                    {
                                        r = (int)ptr1[2];
                                    }
                                    break;
                            }

                            ptr1[0] = (byte)b;
                            ptr1[1] = (byte)g;
                            ptr1[2] = (byte)r;

                            ptr = ptr + bytesPerPixel;
                            ptr1 = ptr1 + bytesPerPixel;
                        }

                        ptr = ptr + remain;
                        ptr1 = ptr1 + remain;
                    }
                }

                image1.UnlockBits(fileData);
                image2.UnlockBits(fileData1);

                return image2;
            }
            catch (Exception ex)
            {
                return new Bitmap(ImageFactory.Draw(ex.Message));
            }
        }
Exemplo n.º 38
0
 internal static void ToColorSpace(Rgb color, Rgb item) {
     item.R = color.R;
     item.G = color.G;
     item.B = color.B;
 }
Exemplo n.º 39
0
        public static Rgb GetRgb(System.Drawing.Point point, Mat img)
        {
            Rgb rgb = new Rgb();

            rgb.Red = img.GetData(point.Y, point.X)[2];
            rgb.Green = img.GetData(point.Y, point.X)[1];
            rgb.Blue = img.GetData(point.Y, point.X)[0];

            return rgb;

        }
Exemplo n.º 40
0
 internal static Rgb ToColor(Rgb item) {
     return item;
 }
Exemplo n.º 41
0
        /// <summary>
        /// Channel filter with RGB
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>Bitmap.</returns>
        public Bitmap Channel(Bitmap file, Rgb filter)
        {
            try
            {
                int red = 0;
                int blue = 0;
                int green = 0;

                switch (filter)
                {
                    case Rgb.Blue:
                        red = -255;
                        green = -255;
                        break;

                    case Rgb.Green:
                        blue = -255;
                        red = -255;
                        break;

                    case Rgb.Red:
                        blue = -255;
                        green = -255;
                        break;
                }

                return Balance(file, red, blue, green);
            }
            catch (Exception ex)
            {
                return new Bitmap(ImageFactory.Draw(ex.Message));
            }
        }
Exemplo n.º 42
0
            internal static void ToColorSpace(Rgb color, Lab item) {
                var xyz = new Xyz();
                xyz.Initialize(color);

                var white = XyzConverter.WhiteReference;
                var x = PivotXyz(xyz.X / white.X);
                var y = PivotXyz(xyz.Y / white.Y);
                var z = PivotXyz(xyz.Z / white.Z);

                item.L = Math.Max(0, 116 * y - 16);
                item.A = 500 * (x - y);
                item.B = 200 * (y - z);
            }
Exemplo n.º 43
0
        internal static Hsb ConvertToHsb(Rgb rgb)
        {
            // By: <a href="http://blogs.msdn.com/b/codefx/archive/2012/02/09/create-a-color-picker-for-windows-phone.aspx" title="MSDN" target="_blank">Yi-Lun Luo</a>
            var r = rgb.R;
            var g = rgb.G;
            var b = rgb.B;

            var max = Max(r, g, b);
            var min = Min(r, g, b);
            var chroma = max - min;
            var hue2 = 0d;
            if (chroma != 0)
            {
                if (max == r)
                {
                    hue2 = (g - b) / chroma;
                }
                else if (max == g)
                {
                    hue2 = (b - r) / chroma + 2;
                }
                else
                {
                    hue2 = (r - g) / chroma + 4;
                }
            }
            var hue = hue2 * 60;
            if (hue < 0)
            {
                hue += 360;
            }
            var brightness = max;
            double saturation = 0;
            if (chroma != 0)
            {
                saturation = chroma / brightness;
            }
            return new Hsb
            {
                H = hue,
                S = saturation,
                B = brightness
            };
        }
Exemplo n.º 44
0
            internal static void ToColorSpace(Rgb color, Xyz item) {
                var r = PivotRgb(color.R / 255.0);
                var g = PivotRgb(color.G / 255.0);
                var b = PivotRgb(color.B / 255.0);

                item.X = r * 0.4124 + g * 0.3576 + b * 0.1805;
                item.Y = r * 0.2126 + g * 0.7152 + b * 0.0722;
                item.Z = r * 0.0193 + g * 0.1192 + b * 0.9505;
            }
Exemplo n.º 45
0
        private Image<Rgb, byte> CreateAvgDepthColumnsBumper(Image<Rgb, byte> ocvDepthBumper)
        {
            double lastColumnAvg = 0;
              Rgb columnPixel = new Rgb(lastColumnAvg, 0, 0);

              Image<Rgb, byte> ocvAvgDepthColumns = ocvDepthBumper.Copy();
              for (int column = 0; column < ocvAvgDepthColumns.Width; column++)
              {
            double sum = 0;
            for (int row = 0; row < ocvAvgDepthColumns.Height; row++)
            {
              sum += ocvAvgDepthColumns[row, column].Green;
              ocvAvgDepthColumns[row, column] = columnPixel;
            }

            lastColumnAvg = sum / ocvAvgDepthColumns.Height;
            columnPixel = new Rgb(lastColumnAvg, 0, 0);
              }
              return ocvAvgDepthColumns;
        }
Exemplo n.º 46
0
        private void DrawEdge(ref Image<Rgb, byte> debugImage, LineSegment2D edge, Rgb color)
        {
            debugImage.Draw(edge, color, 10);

            var p1 = edge.P1;
            var p2 = edge.P2;

            var minX = Math.Min(p1.X, p2.X);
            var minY = Math.Min(p1.Y, p2.Y);
            var maxX = Math.Max(p1.X, p2.X);
            var maxY = Math.Max(p1.Y, p2.Y);

            var centerX = minX + (maxX - minX) / 2;
            var centerY = minY + (maxY - minY) / 2;

            debugImage.Draw(string.Format("{0:F1}", edge.Length), ref EmguFontBig, new Point(centerX, centerY), color);
        }
Exemplo n.º 47
0
        private Image<Rgb, byte> CreateAvgHighDepthColumnsBumper(Image<Gray, byte> ocvHighDepthBumper)
        {
            double lastColumnAvg = 0;
              Rgb columnPixel = new Rgb(lastColumnAvg, lastColumnAvg, lastColumnAvg);

              Image<Rgb, byte> ocvAvgHighDepthColumns = ocvHighDepthBumper.Convert<Rgb, byte>();
              for (int column = 0; column < ocvHighDepthBumper.Width; column++)
              {
            double sum = 0;
            for (int row = 0; row < ocvHighDepthBumper.Height; row++)
            {
              sum += ocvHighDepthBumper[row, column].Intensity;
              ocvAvgHighDepthColumns[row, column] = columnPixel;
            }

            lastColumnAvg = sum / ocvAvgHighDepthColumns.Height;
            columnPixel = new Rgb(lastColumnAvg, lastColumnAvg, lastColumnAvg);
              }
              return ocvAvgHighDepthColumns;
        }
Exemplo n.º 48
0
        public static Rgb YuvToRgb(double y, double u, double v)
        {
            Rgb rgb = new Rgb
            {
                Red = Convert.ToInt32((y + 1.139837398373983740*v)*255),
                Green = Convert.ToInt32((
                    y - 0.3946517043589703515*u - 0.5805986066674976801*v)*255),
                Blue = Convert.ToInt32((y + 2.032110091743119266*u)*255)
            };


            return rgb;
        }
Exemplo n.º 49
0
 public SetBackgroundColor(byte init)
     : base(init)
 {
     this._color = new Rgb(init);
 }
Exemplo n.º 50
0
        private Image<Rgb, byte> CreateDepthMaskOnColorBumper(Image<Rgb, byte> ocvColorBumper, Image<Gray, byte> ocvGrayDepthBumper)
        {
            Image<Rgb, byte> ocvDepthMaskOnColorBumper = ocvColorBumper.Copy();

              for (int column = 0; column < ocvDepthMaskOnColorBumper.Width; column++)
              {
            for (int row = 0; row < ocvDepthMaskOnColorBumper.Height; row++)
            {
              //New_R = CInt((255 - R) * (A / 255.0) + R)
              //New_G = CInt((255 - G) * (A / 255.0) + G)
              //New_B = CInt((255 - G) * (A / 255.0) + B)
              Rgb pixel = ocvDepthMaskOnColorBumper[row, column];
              double alpha = ocvGrayDepthBumper[row, column].Intensity / 255;
              if (alpha < 0.45)
            alpha = 0;
              double newR = pixel.Red * alpha;
              double newG = pixel.Green * alpha;
              double newB = pixel.Blue * alpha;
              ocvDepthMaskOnColorBumper[row, column] = new Rgb(newR, newG, newB);
            }
              }
              return ocvDepthMaskOnColorBumper;
        }
Exemplo n.º 51
0
        public static WriteableBitmap DrawBlobBoundingBoxsAroundCroppedBitmap(WriteableBitmap writeableBitmap,
           WriteableBitmap gradientBitmapRef, WriteableBitmap realBitmapRef, int returnBitmapIndex)
        {
            Bitmap normalBitmap = BitmapFromWriteableBitmap(writeableBitmap);
               var cvImage = new Image<Gray, byte>(new Bitmap(normalBitmap));

               if (cvImage != null)
               {
               Image<Gray, byte> greyImg = cvImage.Convert<Gray, byte>();

               Image<Gray, Byte> greyThreshImg = greyImg.ThresholdBinaryInv(new Gray(150), new Gray(255));

               Emgu.CV.Cvb.CvBlobs resultingImgBlobs = new Emgu.CV.Cvb.CvBlobs();
               Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
               uint numWebcamBlobsFound = bDetect.Detect(greyThreshImg, resultingImgBlobs);

               Image<Rgb, byte> blobImg = greyThreshImg.Convert<Rgb, byte>();
               Rgb red = new Rgb(255, 0, 0);

               int blobNumber = 0;

               foreach (Emgu.CV.Cvb.CvBlob targetBlob in resultingImgBlobs.Values)
               {
                   int imageArea = blobImg.Width*blobImg.Height;
                   int blobArea = targetBlob.Area;
                   int blobBoundingBoxArea = targetBlob.BoundingBox.Width*targetBlob.BoundingBox.Height;

                   if (blobArea > 200.0 && blobBoundingBoxArea < (imageArea*0.99))
                   {
                       blobNumber++;
                       Rectangle rectangle = targetBlob.BoundingBox;
                       Rect convertedRect = new Rect(rectangle.X - 10, rectangle.Y - 10, rectangle.Width + 20,
                           rectangle.Height + 20);
                       //BitmapColorer.DrawRectangle(writeableBitmap, convertedRect);

                       writeableBitmap = writeableBitmap.Crop(rectangle.X - 10, rectangle.Y - 10, rectangle.Width + 20,
                           rectangle.Height + 20);
                       gradientBitmapRef = gradientBitmapRef.Crop(rectangle.X - 10, rectangle.Y - 10,
                           rectangle.Width + 20, rectangle.Height + 20);
                       realBitmapRef = realBitmapRef.Crop(rectangle.X - 10, rectangle.Y - 10, rectangle.Width + 20,
                           rectangle.Height + 20);
                   }
               }
               }
               if (returnBitmapIndex == 1)
               {
               return writeableBitmap;
               }
               else if (returnBitmapIndex == 2)
               {
               return gradientBitmapRef;
               }
               else
               {
               return realBitmapRef;
               }
        }
Exemplo n.º 52
0
        /// <summary>
        /// Get UV Map of a PXCMImage.
        /// </summary>
        /// <param name="image">PXCMImage</param>
        /// <returns>UVMap as EmguCV image.</returns>
        public static Image<Rgb, float> GetDepthUvMap(PXCMImage image)
        {
            var inputWidth = (int)image.info.width;
            var inputHeight = (int)image.info.height;

            var uvMap = new Image<Rgb, float>(inputWidth, inputHeight);

            PXCMImage.ImageData cdata;
            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH, out cdata) <
                pxcmStatus.PXCM_STATUS_NO_ERROR) return uvMap;

            var uv = new float[inputHeight * inputWidth * 2];

            // read UV
            var pData = cdata.buffer.planes[2];
            Marshal.Copy(pData, uv, 0, inputWidth * inputHeight * 2);
            image.ReleaseAccess(ref cdata);

            Parallel.For(0, uv.Length / 2, i =>
            {
                var j = i * 2;
                //Console.WriteLine(j + ": " + uv[j] * 255.0 + ", " + uv[j + 1] * 255.0);
                uvMap[(j / 2) / inputWidth, (j / 2) % inputWidth] = new Rgb(uv[j] * 255.0, uv[j + 1] * 255.0, 0);
            });

            return uvMap;
        }
 /// <summary>
 /// Channel filter
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="comparingImage">The comparing image.</param>
 /// <param name="filter">The filter.</param>
 /// <returns>Image.</returns>
 public static Image Channel(this Image image, Image comparingImage,  Rgb filter)
 {
     ImageFilter imageFilter = new ImageFilter();
     return imageFilter.Channel(new Bitmap(image), new Bitmap(comparingImage), filter);
 }
Exemplo n.º 54
0
        public static WriteableBitmap DrawBlobBoundingBoxsCV(WriteableBitmap writeableBitmap, WriteableBitmap gradientBitmapRef, WriteableBitmap realBitmapRef)
        {
            Bitmap normalBitmap = BitmapFromWriteableBitmap(writeableBitmap);
               var cvImage = new Image<Gray, byte>(new Bitmap(normalBitmap));

               //var classifications = ClassifyBitmap( writeableBitmap, cvImage );
               if (cvImage != null)
               {
               // This takes our nice looking color png and converts it to black and white
               Image<Gray, byte> greyImg = cvImage.Convert<Gray, byte>();

               // We again threshold it based on brightness...BUT WE INVERT THE PNG. BLOB DETECTOR DETECTS WHITE NOT BLACK
               // this will esentially eliminate the color differences
               // you could also do cool things like threshold only certain colors here for a color based blob detector
               Image<Gray, Byte> greyThreshImg = greyImg.ThresholdBinaryInv(new Gray(150), new Gray(255));

               Emgu.CV.Cvb.CvBlobs resultingImgBlobs = new Emgu.CV.Cvb.CvBlobs();
               Emgu.CV.Cvb.CvBlobDetector bDetect = new Emgu.CV.Cvb.CvBlobDetector();
               uint numWebcamBlobsFound = bDetect.Detect(greyThreshImg, resultingImgBlobs);

               // This is a simple way of just drawing all blobs reguardless of their size and not iterating through them
               // It draws on top of whatever you input. I am inputting the threshold image. Specifying an alpha to draw with of 0.5 so its half transparent.
               //Emgu.CV.Image<Bgr, byte> blobImg = bDetect.DrawBlobs(webcamThreshImg, resultingWebcamBlobs, Emgu.CV.Cvb.CvBlobDetector.BlobRenderType.Default, 0.5);

               // Here we can iterate through each blob and use the slider to set a threshold then draw a red box around it
               Image<Rgb, byte> blobImg = greyThreshImg.Convert<Rgb, byte>();
               Rgb red = new Rgb(255, 0, 0);

               int blobNumber = 0;

               // Lets try and iterate the blobs?
               foreach (Emgu.CV.Cvb.CvBlob targetBlob in resultingImgBlobs.Values)
               {
                   int imageArea = blobImg.Width*blobImg.Height;
                   int blobArea = targetBlob.Area;
                   int blobBoundingBoxArea = targetBlob.BoundingBox.Width*targetBlob.BoundingBox.Height;

                   // Only use blobs with area greater than some threshold
                   // If the blob bounding rect is basically size of the whole image ignore it for now
                   if (blobArea > 200.0 && blobBoundingBoxArea < (imageArea*0.99))
                   {
                       Rectangle rectangle = targetBlob.BoundingBox;

                       int CentroidX = (int)targetBlob.Centroid.X;
                       int CentroidY = (int)targetBlob.Centroid.Y;

                       int croppedWidth = rectangle.Width + 50;
                       int croppedHeight = rectangle.Height + 50;

                       int CroppedX = CentroidX - (int)(croppedWidth / 2.0);
                       int CroppedY = CentroidY - (int)(croppedHeight / 2.0);

                       var croppedBlobBitmap = writeableBitmap.Crop(CroppedX, CroppedY, croppedWidth, croppedHeight);
                       var croppedGradientBlobBitmap = gradientBitmapRef.Crop(CroppedX, CroppedY, croppedWidth, croppedHeight);
                       var croppedRealBitmapRef = realBitmapRef.Crop(CroppedX, CroppedY, croppedWidth, croppedHeight);

                       double blobAngle = -RadianToDegree(CalculateBlobAngle(targetBlob));

                       CroppedX = (int) (croppedWidth/2.0);
                       CroppedY = (int) (croppedHeight/2.0);

                       var rotatedandCroppedBlobBitmap = RotateWriteableBitmap(croppedBlobBitmap, blobAngle);
                       var rotatedGradientBlobBitmap = RotateColorWriteableBitmap(croppedGradientBlobBitmap, blobAngle);
                       var rotatedRealBitmapRef = RotateColorWriteableBitmap(croppedRealBitmapRef, blobAngle);

                       var refinedBitmap = DrawBlobBoundingBoxsAroundCroppedBitmap(rotatedandCroppedBlobBitmap, rotatedGradientBlobBitmap, rotatedRealBitmapRef, 1);
                       rotatedGradientBlobBitmap = DrawBlobBoundingBoxsAroundCroppedBitmap(rotatedandCroppedBlobBitmap, rotatedGradientBlobBitmap, rotatedRealBitmapRef, 2);
                       rotatedRealBitmapRef = DrawBlobBoundingBoxsAroundCroppedBitmap(rotatedandCroppedBlobBitmap, rotatedGradientBlobBitmap, rotatedRealBitmapRef, 3);

                       var areaCheck = refinedBitmap.PixelHeight*refinedBitmap.PixelWidth;

                       if (areaCheck >= 200)
                       {
                           blobNumber++;

                           var thresholded = refinedBitmap.Clone();
                           ThresholdBitmap(thresholded, 10, false);
                           BitmapColorer.ColorBitmap(thresholded);

                           System.Windows.Media.Color blobColor = PixelColorOfCentralBlob(thresholded);
                           BitmapColorer.EraseAllButCertainColorandWhite(thresholded, blobColor);

                           var shouldFlip = shouldFlipThresholdedBitmap(thresholded, blobColor);

                           if (shouldFlip)
                           {
                               thresholded = thresholded.Rotate(180);
                               rotatedGradientBlobBitmap = rotatedGradientBlobBitmap.Rotate(180);
                               rotatedRealBitmapRef = rotatedRealBitmapRef.Rotate(180);
                           }

                           var orientedBitmap = NormalizeBitmapSize(thresholded);
                           var orientedGradientBitmap = NormalizeBitmapSize(rotatedGradientBlobBitmap);
                           var orientedRealBitmap = NormalizeBitmapSize(rotatedRealBitmapRef);

                           ApplyBlobMaskToOtherBitmaps(orientedBitmap, orientedGradientBitmap, orientedRealBitmap, blobColor);

                           string fileName1 = saveDirectory + "\\croppedBlob" + blobNumber + ".png";

                           ExtensionMethods.Save(orientedRealBitmap, fileName1);
                       }
                   }
               }
               }

               return writeableBitmap;
        }