//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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public xyYColor ToxyY(LChabColor color) { if (color == null) { throw new ArgumentNullException("color"); } XYZColor xyzColor = ToXYZ(color); xyYColor result = ToxyY(xyzColor); return(result); }
public LinearRGBColor ToLinearRGB(LChabColor color) { if (color == null) { throw new ArgumentNullException("color"); } XYZColor xyzColor = ToXYZ(color); LinearRGBColor result = ToLinearRGB(xyzColor); return(result); }
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)); }
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_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)); }
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)); }
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)); } }
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); }
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); }
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)); } }
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); }
/// <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); }
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()); }
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; }
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()); }