Пример #1
0
        /// <summary>
        /// Convert to CIE from RGB
        /// </summary>
        /// <param name="R">Set Red</param>
        /// <param name="G">Set Green</param>
        /// <param name="B">Set Blue</param>
        /// <param name="Scale">Set scale</param>
        /// <returns></returns>
        public static CIELabColor CIELabFromRGB(float R, float G, float B, float Scale)
        {
            float    inv_scale = 1f / Scale;
            XYZColor xyz       = XYZColor.FromRGB(R * inv_scale, G * inv_scale, B * inv_scale);

            return(CIELabColor.FromXYZ(xyz));
        }
Пример #2
0
        /**
         * Calculate the euclidean distance between two Cie-Lab colors (DeltaE).
         * http://www.easyrgb.com/index.php?X=DELT&H=03#text3
         */

        /// <summary>
        /// Calculate the euclidean distance between two Cie-Lab colors (DeltaE).
        /// </summary>
        /// <param name="lhs">Left Hand Side</param>
        /// <param name="rhs">Right Hand Side</param>
        /// <returns></returns>
        public static float DeltaE(CIELabColor lhs, CIELabColor rhs)
        {
            return((float)Math.Sqrt(
                       (float)Math.Pow((lhs.L - rhs.L), 2) +
                       (float)Math.Pow((lhs.a - rhs.a), 2) +
                       (float)Math.Pow((lhs.b - rhs.b), 2)));
        }
Пример #3
0
        /**
         * Get human readable name from a Color.
         */

        /// <summary>
        /// Get Color Name
        /// </summary>
        /// <param name="InColor">Set in-color</param>
        /// <returns></returns>
        public static string GetColorName(Color InColor)
        {
            CIELabColor lab = CIELabColor.FromRGB(InColor);

            string name = "Unknown";
            float  diff = (float)double.PositiveInfinity;

            foreach (KeyValuePair <string, CIELabColor> kvp in ColorNameLookup)
            {
                float dist = (float)Math.Abs(DeltaE(lab, kvp.Value));

                if (dist < diff)
                {
                    diff = dist;
                    name = kvp.Key;
                }
            }

            return(name);
        }