Exemple #1
0
        //this is the core of the algorithm. the output image is computed in the HCL color space
        //using the gray scale visible image for Luminance and thermal image for Hue
        private unsafe void FuseLuminances()
        {
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65
            };

            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                       ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
            int *dst = (int *)data.Scan0;

            for (int i = 0; i < visibles.Length; i++)
            {
                double luminance = visibles[i] * 100; //0..100
                double hue       = Math.Min(1, thermals[i] * hueGain);
                hue = 300 - (int)(hue * 300);         //0..300

                //compose HCL color
                var hclColor = new LChabColor(luminance, chroma, hue);

                //convert to RGB and put in bitmap
                Color color = converter.ToRGB(hclColor);
                *     dst++ = (color.R << 16) | (color.G << 8) | color.B;
            }
            bitmap.UnlockBits(data);
        }
Exemple #2
0
        public void SetPixel(int x, int y, Vector4 color)
        {
            var clampedColor   = Vector4.Clamp(color, Vector4.Zero, Vector4.One);
            var linearRgbColor = new LinearRGBColor(clampedColor.X, clampedColor.Y, clampedColor.Z);
            var sRgbColor      = _converter.ToRGB(linearRgbColor);

            SetPixel(x, y, new MonoColor((float)sRgbColor.R, (float)sRgbColor.G, (float)sRgbColor.B));
        }
Exemple #3
0
        public void Convert_Lab_to_RGB(DataRow row)
        {
            var inputLab    = row.GetLabColor();
            var expectedRGB = row.GetRGBColor();
            var actualRGB   = _converter.ToRGB(inputLab);

            try
            {
                Assert.That(actualRGB, Is.EqualTo(expectedRGB)
                            .Using(new ColorVectorComparer(new DoubleDeltaComparer(0.00912))));
            }
            catch (AssertionException ex) { RethrowException(ex, row); }
        }
Exemple #4
0
        public static Color Lab2Color(LabColor color)
        {
            Color output    = new Color();
            var   converter = new ColourfulConverter {
                WhitePoint = Illuminants.D50, TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB
            };
            RGBColor rgbColor = converter.ToRGB(color);

            output.r = (float)rgbColor.R;
            output.g = (float)rgbColor.G;
            output.b = (float)rgbColor.B;
            output.a = 1.0f;
            return(output);
        }
Exemple #5
0
        private Color[] GetNColorsForBarGraph(int n)
        {
            var converter = new ColourfulConverter();
            var start     = (L : 65, a : 65, b : -15);
            var end       = (L : 25, a : -40, b : -35);
            var delta     = (L : end.L - start.L, a : end.a - start.a, b : end.b - start.b);
            var colors    = Enumerable.Range(0, n)
                            .Select(x => (double)x / (n - 1))
                            .Select(x => (L: start.L + delta.L * x, a: start.a + delta.a * x, b: start.b + delta.b * x))
                            .Select(x => new LabColor(x.L, x.a, x.b))
                            .Select(x => converter.ToRGB(x).ToColor())
                            .Reverse()
                            .ToArray();

            return(colors);
        }
        public void Convert_XYZ_D65_to_sRGB(double x, double y, double z, double r, double g, double b)
        {
            // arange
            var input     = new XYZColor(x, y, z);
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65, TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB
            };

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

            // assert
            Assert.Equal(output.WorkingSpace, RGBColor.DefaultWorkingSpace);
            Assert.Equal(output.R, r, DoubleComparer);
            Assert.Equal(output.G, g, DoubleComparer);
            Assert.Equal(output.B, b, DoubleComparer);
        }
        public void Convert_XYZ_D65_to_sRGB(double x, double y, double z, double r, double g, double b)
        {
            // arange
            var input     = new XYZColor(x, y, z);
            var converter = new ColourfulConverter {
                WhitePoint = Illuminants.D65, TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB
            };

            // act
            RGBColor output = converter.ToRGB(input);

            // assert
            Assert.That(output.WorkingSpace, Is.EqualTo(RGBColor.DefaultWorkingSpace));
            Assert.That(output.R, Is.EqualTo(r).Using(DoubleComparer));
            Assert.That(output.G, Is.EqualTo(g).Using(DoubleComparer));
            Assert.That(output.B, Is.EqualTo(b).Using(DoubleComparer));
        }
Exemple #8
0
 public double ColourfulConvert()
 {
     return(ColourfulConverter.ToRGB(XYZColor).R);
 }
Exemple #9
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;
        }