Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
    public void Equals_Same()
    {
        var first  = new LChabColor(l: 10, c: 20.5, h: 45.445);
        var second = new LChabColor(l: 10, c: 20.5, h: 45.445);

        CustomAssert.EqualsWithHashCode(first, second);
    }
Ejemplo n.º 3
0
    public void Equals_Different()
    {
        var first  = new LChabColor(l: 11, c: 20.5, h: 45.445);
        var second = new LChabColor(l: 10, c: 20.5, h: 45.445);

        CustomAssert.NotEqualsWithHashCode(first, second);
    }
Ejemplo n.º 4
0
        public void LChabColor()
        {
            var first  = new LChabColor(10, 20.5, 45.445);
            var second = new LChabColor(10, 20.5, 45.445);

            Assert.Equal(first, (object)second);
        }
Ejemplo n.º 5
0
    public void VectorCtor()
    {
        var first  = new LChabColor(l: 10, c: 20.5, h: 45.445);
        var vector = new[] { 10, 20.5, 45.445 };
        var second = new LChabColor(vector);

        CustomAssert.EqualsWithHashCode(first, second);
        Assert.Equal(vector, second.Vector);
    }
Ejemplo n.º 6
0
    public void FromSaturationCtor()
    {
        var          first      = new LChabColor(l: 10, c: 3, h: 20);
        const double saturation = 30d;
        var          second     = LChabColor.FromSaturation(lightness: 10, hue: 20, saturation);

        CustomAssert.EqualsWithHashCode(first, second);
        Assert.Equal(saturation, second.Saturation);
    }
Ejemplo n.º 7
0
    public void Dctor()
    {
        const double l1 = 10;
        const double c1 = 20.5;
        const double h1 = 45.445;

        var(l2, c2, h2) = new LChabColor(l1, c1, h1);
        Assert.Equal(l1, l2);
        Assert.Equal(c1, c2);
        Assert.Equal(h1, h2);
    }
Ejemplo n.º 8
0
        public LChabColor ToLChab(XYZColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            LabColor   labColor = ToLab(color);
            LChabColor result   = ToLChab(labColor);

            return(result);
        }
        public HunterLabColor ToHunterLab(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor       xyzColor = ToXYZ(color);
            HunterLabColor result   = ToHunterLab(xyzColor);

            return(result);
        }
Ejemplo n.º 10
0
    public void LChabToRgb()
    {
        var inputLChab      = new LChabColor(53.9, 81.52, 30.2);
        var rgbWorkingSpace = RGBWorkingSpaces.sRGB;

        var lChabToRgb = new ConverterBuilder().FromLChab(Illuminants.D50).ToRGB(rgbWorkingSpace).Build();
        var outputRgb  = lChabToRgb.Convert(inputLChab); // RGB [R=0.94, G=0.2, B=0.25]

        Assert.Equal(0.9370373270715214, outputRgb.R);
        Assert.Equal(0.2000445268236402, outputRgb.G);
        Assert.Equal(0.2509818153127169, outputRgb.B);
    }
Ejemplo n.º 11
0
        public xyYColor ToxyY(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor xyzColor = ToXYZ(color);
            xyYColor result   = ToxyY(xyzColor);

            return(result);
        }
Ejemplo n.º 12
0
        public LinearRGBColor ToLinearRGB(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor       xyzColor = ToXYZ(color);
            LinearRGBColor result   = ToLinearRGB(xyzColor);

            return(result);
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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
            var output = Converter.ToLab(input);

            // assert
            Assert.Equal(output.L, l2, DoubleComparer);
            Assert.Equal(output.a, a, DoubleComparer);
            Assert.Equal(output.b, b, DoubleComparer);
        }
        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));
        }
Ejemplo n.º 16
0
        public void Convert_Lab_to_LCHab(double l, double a, double b, double l2, double c, double h)
        {
            // arrange
            var input = new LabColor(l, a, b);

            // act
            LChabColor output = Converter.ToLChab(input);

            // assert
            Assert.That(output.L, Is.EqualTo(l2).Using(DoubleComparer));
            Assert.That(output.C, Is.EqualTo(c).Using(DoubleComparer));
            Assert.That(output.h, Is.EqualTo(h).Using(DoubleComparer));
        }
Ejemplo n.º 17
0
    public void SamplesLChab()
    {
        // red
        var c1 = new LChabColor(53.9, 81.52, 30.2);

        // white
        var c2 = new LChabColor(100, 0, 0);

        // gray
        var c3 = new LChabColor(53.39, 0, 0);

        // black
        var c4 = new LChabColor(0, 0, 0);
    }
        public void Adapt_LChab_D50_To_D65(double l1, double c1, double h1, double l2, double c2, double h2)
        {
            // arrange
            var input = new LChabColor(l1, c1, h1, Illuminants.D50);
            var expectedOutput = new LChabColor(l2, c2, h2);
            var converter = new ColourfulConverter { TargetLabWhitePoint = Illuminants.D65 };

            // action
            LChabColor output = converter.Adapt(input);

            // assert
            Assert.That(output.L, Is.EqualTo(expectedOutput.L).Using(DoubleRoundingComparer));
            Assert.That(output.C, Is.EqualTo(expectedOutput.C).Using(DoubleRoundingComparer));
            Assert.That(output.h, Is.EqualTo(expectedOutput.h).Using(DoubleRoundingComparer));
        }
Ejemplo n.º 19
0
        public Color Saturate(double amount = 1)
        {
            using (ColorToolExtensions.BorrowColourfulConverter(out var conv))
            {
                LChabColor lch = conv.ToLChab(_rgb);
                double     C   = lch.C + (LabConsts.Kn * amount);
                if (C < 0)
                {
                    C = 0;
                }
                LChabColor lch2 = new LChabColor(lch.L, C, lch.h);
                RGBColor   rgb  = conv.ToRGB(lch2);

                return(Alpha(rgb, Alpha(), true));
            }
        }
Ejemplo n.º 20
0
        public XYZColor ToXYZ(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            // conversion to Lab
            var      labConverter = new LChabToLabConverter();
            LabColor labColor     = labConverter.Convert(color);

            // conversion to XYZ (incl. adaptation)
            XYZColor result = ToXYZ(labColor);

            return(result);
        }
Ejemplo n.º 21
0
        public LChabColor ToLChab(LabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            // adaptation to target lab white point (LabWhitePoint)
            LabColor adapted = IsChromaticAdaptationPerformed ? Adapt(color) : color;

            // conversion (perserving white point)
            var        converter = new LabToLChabConverter();
            LChabColor result    = converter.Convert(adapted);

            return(result);
        }
Ejemplo n.º 22
0
        public void Adapt_LChab_D50_To_D65(double l1, double c1, double h1, double l2, double c2, double h2)
        {
            // arrange
            var input          = new LChabColor(l1, c1, h1, Illuminants.D50);
            var expectedOutput = new LChabColor(l2, c2, h2);
            var converter      = new ColourfulConverter {
                TargetLabWhitePoint = Illuminants.D65
            };

            // action
            LChabColor output = converter.Adapt(input);

            // assert
            Assert.That(output.L, Is.EqualTo(expectedOutput.L).Using(DoubleRoundingComparer));
            Assert.That(output.C, Is.EqualTo(expectedOutput.C).Using(DoubleRoundingComparer));
            Assert.That(output.h, Is.EqualTo(expectedOutput.h).Using(DoubleRoundingComparer));
        }
Ejemplo n.º 23
0
        public LChabColor ToLChab <T>(T color) where T : IColorVector
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            LChabColor converted = color as LChabColor;

            if (converted != null)
            {
                return(converted);
            }
            else
            {
                dynamic source = color;

                return(ToLChab(source));
            }
        }
Ejemplo n.º 24
0
        public LabColor ToLab(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            // conversion (perserving white point)
            var      converter = new LChabToLabConverter();
            LabColor unadapted = converter.Convert(color);

            if (!IsChromaticAdaptationPerformed)
            {
                return(unadapted);
            }

            // adaptation to target lab white point (LabWhitePoint)
            LabColor adapted = Adapt(unadapted);

            return(adapted);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adapts LChab color from the source white point to white point set in <see cref="TargetLabWhitePoint"/>.
        /// </summary>
        public LChabColor Adapt(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            if (!IsChromaticAdaptationPerformed)
            {
                throw new InvalidOperationException("Cannot perform chromatic adaptation, provide chromatic adaptation method and white point.");
            }

            if (color.WhitePoint.Equals(TargetLabWhitePoint))
            {
                return(color);
            }

            LabColor   labColor = ToLab(color);
            LChabColor result   = ToLChab(labColor);

            return(result);
        }
Ejemplo n.º 26
0
    public void ToString_Simple()
    {
        var color = new LChabColor(l: 10, c: 20.5, h: 45.445);

        Assert.Equal("LChab [L=10, C=20.5, h=45.45]", color.ToString());
    }
Ejemplo n.º 27
0
 public void LChabColor()
 {
     var color = new LChabColor(10, 20.5, 45.445);
     Assert.AreEqual("LChab [L=10, C=20.5, h=45.45]", color.ToString());
 }
        /// <summary>
        /// Adapts LChab color from the source white point to white point set in <see cref="TargetLabWhitePoint"/>.
        /// </summary>
        public LChabColor Adapt(LChabColor color)
        {
            if (color == null) throw new ArgumentNullException("color");

            if (!IsChromaticAdaptationPerformed)
                throw new InvalidOperationException("Cannot perform chromatic adaptation, provide chromatic adaptation method and white point.");

            if (color.WhitePoint.Equals(TargetLabWhitePoint))
                return color;

            LabColor labColor = ToLab(color);
            LChabColor result = ToLChab(labColor);
            return result;
        }
Ejemplo n.º 29
0
        public void LChabColor()
        {
            var color = new LChabColor(10, 20.5, 45.445);

            Assert.Equal("LChab [L=10, C=20.5, h=45.45]", color.ToString());
        }