public CustomPixel(Color color, int x, int y)
 {
     Color  = color;
     this.x = x;
     this.y = y;
     Point  = new Point3D(color.R, color.G, color.B);
     D      = ((color.R + color.G + color.B) / 3);
     R      = Color.R;
     G      = Color.G;
     B      = Color.B;
     LAB    = converter.ToLab(new RGBColor(color.R / 255.00, color.G / 255.00, color.B / 255.00));
 }
Example #2
0
        private bool Compare(Bitmap bitmap, int x, int y, Color color)
        {
            var difference = new CIE76ColorDifference();
            var converter  = new ColourfulConverter()
            {
                WhitePoint = Illuminants.D65
            };
            var rgbColor = bitmap.GetPixel(bitmap.Width - x, bitmap.Height - y);
            var labColor = converter.ToLab(new RGBColor(rgbColor));
            var cmpColor = converter.ToLab(new RGBColor(color));
            var diff     = difference.ComputeDifference(labColor, cmpColor);

            return(Math.Abs(diff) < ColorDiffThreashold);
        }
Example #3
0
        private static LabColor ToLabColor(Color color)
        {
            var converter = new ColourfulConverter {
                TargetLabWhitePoint = Illuminants.D65
            };

            return(converter.ToLab(new RGBColor(color.R / 255.0, color.G / 255.0, color.B / 255.0)));
        }
Example #4
0
        private static double GetColorDifference(Color a, Color b)
        {
            var aNormalized = new[] { (double)a.R / 255, (double)a.G / 255, (double)a.B / 255 };
            var bNormalized = new[] { (double)b.R / 255, (double)b.G / 255, (double)b.B / 255 };

            var aColor = new RGBColor(aNormalized[0], aNormalized[1], aNormalized[2]);
            var bColor = new RGBColor(bNormalized[0], bNormalized[1], bNormalized[2]);

            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65
            };
            var labA = converter.ToLab(aColor);
            var labB = converter.ToLab(bColor);

            return(Math.Sqrt(Math.Pow(labB.L - labA.L, 2) +
                             Math.Pow(labB.a - labA.a, 2) +
                             Math.Pow(labB.b - labA.b, 2)));
        }
Example #5
0
        public static LabColor Color2Lab(Color color)
        {
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D50, TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB
            };
            RGBColor rgbColor = new RGBColor(color.r, color.g, color.b);
            LabColor output   = converter.ToLab(rgbColor);

            return(output);
        }
        private bool IsSameColorContains(uint[] colors, uint c)
        {
            var difference = new CIE76ColorDifference();
            var converter  = new ColourfulConverter()
            {
                WhitePoint = Illuminants.D65
            };
            var labColor = converter.ToLab(new RGBColor(Color.FromArgb((int)c)));

            foreach (var color in colors)
            {
                var l    = converter.ToLab(new RGBColor(Color.FromArgb((int)color)));
                var diff = difference.ComputeDifference(labColor, l);
                if (Math.Abs(diff) < ColorDiffThreashold)
                {
                    return(true);
                }
            }

            return(false);
        }
        public void Convert_LCHab_to_Lab(double l, double c, double h, double l2, double a, double b)
        {
            // arrange
            var input = new LChabColor(l, c, h);

            // act
            LabColor output = Converter.ToLab(input);

            // assert
            Assert.That(output.L, Is.EqualTo(l2).Using(DoubleComparer));
            Assert.That(output.a, Is.EqualTo(a).Using(DoubleComparer));
            Assert.That(output.b, Is.EqualTo(b).Using(DoubleComparer));
        }
Example #8
0
        private PowDebuff[] GetPowDebuffs(Bitmap bitmap)
        {
            // 右下のアイコンは透過が少しあるため、ピクセル単位の色が完全一致しない。
            // そのため、L*a*b色空間での色差が閾値以内かどうかで判定する。
            var converter = new ColourfulConverter()
            {
                WhitePoint = Illuminants.D65
            };
            var powerBreakCmpLabColor1 = converter.ToLab(PowerBreakCmpColor1);
            var powerBreakCmpLabColor2 = converter.ToLab(PowerBreakCmpColor2);
            var difference             = new CIE76ColorDifference();

            for (int i = 0; i < MaxPowerDebuffCount; i++)
            {
                var x1 = bitmap.Width - 28 - (32 * i);
                var x2 = bitmap.Width - 34 - (32 * i);
                var y  = bitmap.Height - 20;

                var c1 = converter.ToLab(new RGBColor(bitmap.GetPixel(x1, y)));
                var c2 = converter.ToLab(new RGBColor(bitmap.GetPixel(x2, y)));

                var diff1 = difference.ComputeDifference(powerBreakCmpLabColor1, c1);
                var diff2 = difference.ComputeDifference(powerBreakCmpLabColor2, c2);

                if (Math.Abs(diff1) < ColorDiffThreashold &&
                    Math.Abs(diff2) < ColorDiffThreashold)
                {
                    return(new PowDebuff[]
                    {
                        PowerBreak
                    });
                }
            }

            return(new PowDebuff[0]);
        }
        public void Convert_XYZ_to_Lab(double x, double y, double z, double l, double a, double b)
        {
            // arrange
            var input     = new XYZColor(x, y, z);
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65
            };

            // act
            var output = converter.ToLab(input);

            // assert
            Assert.Equal(output.L, l, DoubleComparerLabPrecision);
            Assert.Equal(output.a, a, DoubleComparerLabPrecision);
            Assert.Equal(output.b, b, DoubleComparerLabPrecision);
        }
Example #10
0
        public void Convert_XYZ_to_Lab(double x, double y, double z, double l, double a, double b)
        {
            // arrange
            var input     = new XYZColor(x, y, z);
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65, TargetLabWhitePoint = Illuminants.D65
            };

            // act
            LabColor output = converter.ToLab(input);

            // assert
            Assert.That(output.L, Is.EqualTo(l).Using(DoubleComparerLabPrecision));
            Assert.That(output.a, Is.EqualTo(a).Using(DoubleComparerLabPrecision));
            Assert.That(output.b, Is.EqualTo(b).Using(DoubleComparerLabPrecision));
        }
Example #11
0
        private void WritePixels(Bitmap resizedImage)
        {
            if (_showMsg)
            {
                Console.Write("\tConverting Pixels...");
            }
            var converter = new ColourfulConverter();

            _pixels = new SalientPixel[resizedImage.Width][];
            for (var x = 0; x < resizedImage.Width; x++)
            {
                _pixels[x] = new SalientPixel[resizedImage.Height];
                for (var y = 0; y < resizedImage.Height; y++)
                {
                    var pixelColor = resizedImage.GetPixel(x, y);
                    var input      = new RGBColor(pixelColor.R / 255.0, pixelColor.G / 255.0, pixelColor.B / 255.0);
                    _pixels[x][y] = new SalientPixel(converter.ToLab(input), x, y, _numberOfScales);
                }
            }
            if (_showMsg)
            {
                Console.Write("\tPixels Converted");
            }
        }
Example #12
0
 public double ColourfulConvert()
 {
     return(ColourfulConverter.ToLab(XYZColor).L);
 }
Example #13
0
 public double Distance(Color c1, Color c2)
 {
     return(Cmc.ComputeDifference(Converter.ToLab(new RGBColor(c1)), Converter.ToLab(new RGBColor(c2))));
 }
Example #14
0
 public static LabColor ToLab(RGBColor input)
 {
     return(Converter.ToLab(input));
 }
Example #15
0
 /// <summary>
 /// See https://en.wikipedia.org/wiki/CIELAB_color_space
 /// </summary>
 private static LabColor ToLabColor(int r, int g, int b) =>
 converter.ToLab(new RGBColor((double)r / 255, (double)g / 255, (double)b / 255));
Example #16
0
        private void colorMeasurment()

        {
            if (!IsRun)
            {
                return;
            }
            chart1.Series["palete"].Points.Clear();
            //   float[] T = dtAnalys.Transmittance(numSmoothing, darkData, refrenceData);
            float X = 0;
            float Y = 0;
            float Z = 0;
            float x = X; // ( X / (X + Y + Z)) ;
            float y = Y; // (Y / (X + Y + Z));
            float z = Z; // =( 1 - (x + y) );
            int   k = 0;

            float Kcolor = 0;

            int[] colordt = new int[500];
            if (dt1 == null)
            {
                return;
            }


            //int result;
            //int s = 0;
            //for (int m = 80; m < 1270; m++)
            //{

            //    Math.DivRem(Convert.ToInt32(xvalue [m]), 5, out result);
            //    if (result == 0)
            //    {
            //        colordt [s] = Convert.ToInt32(xvalue  [m]);
            //        s++;
            //    }
            //}

            colordt = colordt.Distinct().ToArray();
            if (rdA.Checked && rd2.Checked)
            {
                for (int m = 0; m < 79; m++)
                {
                    if (m == 78)
                    {
                        X       = X + (A[m - 1] * X2[m - 1] * dt1[m]);
                        Y       = Y + (A[m - 1] * Y2[m - 1] * dt1[m]);
                        Z       = Z + (A[m - 1] * Z2[m - 1] * dt1[m]);
                        Kcolor += (A[m - 1] * Y2[m - 1]);
                    }
                    else
                    {
                        X       = X + (A[m] * X2[m] * dt1[m]);
                        Y       = Y + (A[m] * Y2[m] * dt1[m]);
                        Z       = Z + (A[m] * Z2[m] * dt1[m]);
                        Kcolor += (A[m] * Y2[m]);
                    }
                }
                Kcolor = 100 / Kcolor;
                X      = Kcolor * X;
                Y      = Kcolor * Y;
                Z      = Kcolor * Z;
                x      = X / (X + Y + Z);
                y      = Y / (X + Y + Z);
                z      = 1 - (x + y);
            }
            else if (rdA.Checked && rd10.Checked)
            {
                for (int i = 420; i <= 750; i = i + 5)
                {
                    X       = X + (A[k] * X10[k] * dt1[k]);
                    Y       = Y + (A[k] * Y10[k] * dt1[k]);
                    Z       = Z + (A[k] * Z10[k] * dt1[k]);
                    Kcolor += (A[k] * Y10[k]);
                    k       = k + 1;
                }
                Kcolor = 100 / Kcolor;
                X      = Kcolor * X;
                Y      = Kcolor * Y;
                Z      = Kcolor * Z;
                x      = X / (X + Y + Z);
                y      = Y / (X + Y + Z);
                z      = 1 - (x + y);
            }
            else if (rdD65.Checked && rd10.Checked)
            {
                for (int i = 420; i <= 750; i = i + 5)
                {
                    X       = X + (D65[k] * X10[k] * dt1[k]);
                    Y       = Y + (D65[k] * Y10[k] * dt1[k]);
                    Z       = Z + (D65[k] * Z10[k] * dt1[k]);
                    Kcolor += (D65[k] * Y10[k]);
                    k       = k + 1;
                }
                Kcolor = 100 / Kcolor;
                X      = Kcolor * X;
                Y      = Kcolor * Y;
                Z      = Kcolor * Z;
                x      = X / (X + Y + Z);
                y      = Y / (X + Y + Z);
                z      = 1 - (x + y);
            }

            else if (rdD65.Checked && rd2.Checked)
            {
                //float[] p = new float[200];
                //int countC = 0;
                //for (int m = 0; m < pirple.Length; m = m + 16)
                //{
                //    p[countC] = pirple[m];
                //    countC++;

                //}

                for (int m = 0; m < 79; m++)
                {
                    if (m == 78)
                    {
                        X       = X + (A[m - 1] * X2[m - 1] * dt1[m]);
                        Y       = Y + (A[m - 1] * Y2[m - 1] * dt1[m]);
                        Z       = Z + (A[m - 1] * Z2[m - 1] * dt1[m]);
                        Kcolor += (D65[m - 1] * Y2[m - 1]);
                    }
                    else
                    {
                        X       = X + (D65[m] * X2[m] * dt1[m]);
                        Y       = Y + (D65[m] * Y2[m] * dt1[m]);
                        Z       = Z + (D65[m] * Z2[m] * dt1[m]);
                        Kcolor += (D65[m] * Y2[m]);
                    }
                }
                Kcolor = 100 / Kcolor;
                X      = Kcolor * X;
                Y      = Kcolor * Y;
                Z      = Kcolor * Z;
                x      = X / (X + Y + Z);
                y      = Y / (X + Y + Z);
                z      = 1 - (x + y);
            }

            XYZg.Visible     = true;
            RGBg.Visible     = true;
            CIELuvg.Visible  = true;
            LABg.Visible     = true;
            CIExyYg.Visible  = true;
            CIElchuv.Visible = true;
            LCHABg.Visible   = true;
            //   fchart.LMSg.Visible = true;
            Hunterg.Visible = true;
            CIEXlbl.Text    = "X=" + x.ToString("N4");
            CIEYlbl.Text    = "Y=" + y.ToString("N4");
            CIEZlbl.Text    = "Z=" + z.ToString("N4");



            Colourful.Conversion.ColourfulConverter a = new ColourfulConverter();
            Colourful.XYZColor xyz = new Colourful.XYZColor(x, y, z);
            ColourfulConverter a1  = new ColourfulConverter();

            a1.ToLab(xyz);
            //  lblWithepoint.Text =   a1.WhitePoint.ToString();



            LabColor la = a1.ToLab(xyz);

            CIELlbl.Text = "L=" + la.L.ToString("N4");
            CIEAlbl.Text = "a=" + la.a.ToString("N4");
            CIEBlbl.Text = "b=" + la.b.ToString("N4");



            Colourful.LuvColor luvc = a1.ToLuv(xyz);
            CIELuvLlbl.Text = "L=" + luvc.L.ToString("N4");
            CIELuvUlbl.Text = "u=" + luvc.u.ToString("N4");
            CIELuvVlbl.Text = "v=" + luvc.v.ToString("N4");

            Colourful.xyYColor xyY = a1.ToxyY(xyz);
            CIExyYxlbl.Text  = "x=" + xyY.x.ToString("N4");
            CIExyYylbl.Text  = "y=" + xyY.y.ToString("N4");
            CIExyYy1lbl.Text = "L=" + xyY.Luminance.ToString("N4");
            Colourful.LChuvColor lchuv = a1.ToLChuv(xyz);

            LCHLlbl.Text = "L=" + lchuv.L.ToString("N4");
            LCHClbl.Text = "C=" + lchuv.C.ToString("N4");
            LCHHlbl.Text = "h=" + lchuv.h.ToString("N4");
            Colourful.LChabColor lchab = a1.ToLChab(xyz);

            LCHabLlbl.Text = "L=" + lchab.L.ToString("N4");
            LCHabClbl.Text = "C=" + lchab.C.ToString("N4");
            LCHabhlbl.Text = "h=" + lchab.h.ToString("N4");
            //Colourful.LMSColor lms = a1.ToLMS(xyz);
            //fchart.LMSLbl.Text = "L=" + lms.L.ToString("N4");
            //fchart.LMSMlbl.Text = "M=" + lms.M.ToString("N4");
            //fchart.LMSSlbl.Text = "S=" + lms.S.ToString("N4");
            Colourful.HunterLabColor hunter = a1.ToHunterLab(xyz);
            hunterLlbl.Text = "L=" + hunter.L.ToString("N4");
            Hunteralbl.Text = "a=" + hunter.a.ToString("N4");
            hunterblbl.Text = "b=" + hunter.b.ToString("N4");

            Color rgb = a.ToRGB(xyz);

            Rlbl.Text = "R=" + rgb.R.ToString();
            Glbl.Text = "G=" + rgb.G.ToString();
            Blbl.Text = "B=" + rgb.B.ToString();
            double C  = 1 - (rgb.R / 255f);
            double M  = 1 - (rgb.G / 255f);
            double Y1 = 1 - (rgb.B / 255f);
            double K1 = 1;

            if (C < K1)
            {
                K1 = C;
            }
            if (M < K1)
            {
                K1 = M;
            }
            if (Y1 < K1)
            {
                K1 = Y1;
            }
            if (K1 == 1)
            {
                C  = 0;
                M  = 0;
                Y1 = 0;
            }
            else
            {
                C  = (C - K1) / (1 - K1);
                M  = (M - K1) / (1 - K1);
                Y1 = (Y1 - K1) / (1 - K1);
            }
            lblC.Text = "C=" + C.ToString("N4");
            lblM.Text = "M=" + M.ToString("N4");
            lblY.Text = "Y=" + Y1.ToString("N4");
            lblK.Text = "K=" + K1.ToString("N4");

            int match = FindNearestColor(colormach, rgb);



            chart1.Series["palete"].Points.AddXY(XvalColor[match], YvalColor[match]);
            measurment = false;
        }