Exemple #1
0
    // static function for converting from Color to LABColor
    public static LABColor FromColor(Color c)
    {
        float D65x    = 0.9505f;
        float D65y    = 1.0f;
        float D65z    = 1.0890f;
        float rLinear = c.r;
        float gLinear = c.g;
        float bLinear = c.b;
        float r       = (rLinear > 0.04045f) ? Mathf.Pow((rLinear + 0.055f) / (1f + 0.055f), 2.2f) : (rLinear / 12.92f);
        float g       = (gLinear > 0.04045f) ? Mathf.Pow((gLinear + 0.055f) / (1f + 0.055f), 2.2f) : (gLinear / 12.92f);
        float b       = (bLinear > 0.04045f) ? Mathf.Pow((bLinear + 0.055f) / (1f + 0.055f), 2.2f) : (bLinear / 12.92f);
        float x       = (r * 0.4124f + g * 0.3576f + b * 0.1805f);
        float y       = (r * 0.2126f + g * 0.7152f + b * 0.0722f);
        float z       = (r * 0.0193f + g * 0.1192f + b * 0.9505f);

        x = (x > 0.9505f) ? 0.9505f : ((x < 0f) ? 0f : x);
        y = (y > 1.0f) ? 1.0f : ((y < 0f) ? 0f : y);
        z = (z > 1.089f) ? 1.089f : ((z < 0f) ? 0f : z);
        LABColor lab = new LABColor(0f, 0f, 0f);
        float    fx  = x / D65x;
        float    fy  = y / D65y;
        float    fz  = z / D65z;

        fx    = ((fx > 0.008856f) ? Mathf.Pow(fx, (1.0f / 3.0f)) : (7.787f * fx + 16.0f / 116.0f));
        fy    = ((fy > 0.008856f) ? Mathf.Pow(fy, (1.0f / 3.0f)) : (7.787f * fy + 16.0f / 116.0f));
        fz    = ((fz > 0.008856f) ? Mathf.Pow(fz, (1.0f / 3.0f)) : (7.787f * fz + 16.0f / 116.0f));
        lab.l = 116.0f * fy - 16f;
        lab.a = 500.0f * (fx - fy);
        lab.b = 200.0f * (fy - fz);
        return(lab);
    }
    // Use this for initialization
    void Start()
    {
        mom = (GameObject)Instantiate(Resources.Load("Blob"));
        dad = (GameObject)Instantiate(Resources.Load("Blob"));

        //Separate the two so they aren't covering each other
        mom.transform.position = new Vector2(3, transform.position.y);
        dad.transform.position = new Vector2(-3, transform.position.y);

        //Add markings to the dad
        //GO = (GameObject)Instantiate(Resources.Load("dogmarkings"));
        //GO.transform.parent = dad.transform;
        //GO.transform.position = new Vector3(-3, transform.position.y, -1);

        //Flip the Mommy around so that she faces the Daddy
        mom.transform.eulerAngles = new Vector2(0, 180);

        //Make the Mom red and the Dad green
        LABColor c1 = new LABColor(Color.yellow);
        LABColor c2 = new LABColor(Color.red);
        LABColor c3 = new LABColor(Color.white);
        LABColor c4 = new LABColor(Color.black);
        mom.GetComponent<SpriteRenderer>().color = c1.ToColor();
        dad.GetComponent<SpriteRenderer>().color = c2.ToColor();

        mom.GetComponent<Blob>().addGene<LABColor>("Color", c1, 0, c3, 0);
        dad.GetComponent<Blob>().addGene<LABColor>("Color", c2, 0, c4, 0);

        child = Punnett.cross(mom.GetComponent<Blob>(), dad.GetComponent<Blob>());
        child.transform.position = new Vector2(0, transform.position.y);

        child.GetComponent<SpriteRenderer>().color = child.GetComponent<Blob>().color.ToColor();
    }
Exemple #3
0
    public void RecolorTanks(string team, string htmlColor)
    {
        Color newColor;

        ColorUtility.TryParseHtmlString(htmlColor, out newColor);
        if (LABColor.Compare(new LABColor(newColor), new LABColor(new Color(255, 187, 77))) > 20f)
        {
            if (team == "Blue" && LABColor.Compare(new LABColor(newColor), new LABColor(m_Tanks[1].m_CurrentColor)) > 40f)
            {
                for (int i = 0; i < m_Tanks.Length - missingTanks; i++)
                {
                    if (i % 2 == 0)
                    {
                        m_Tanks [i].Recolor(newColor);
                    }
                }
                m_BlueTeamColor = htmlColor;
                m_Setup.m_BlueTeamText.color  = newColor;
                m_Setup.m_BlueScoreText.color = newColor;
            }
            else if (team == "Red" && LABColor.Compare(new LABColor(newColor), new LABColor(m_Tanks[0].m_CurrentColor)) > 40f)
            {
                for (int i = 0; i < m_Tanks.Length - missingTanks; i++)
                {
                    if (i % 2 != 0)
                    {
                        m_Tanks [i].Recolor(newColor);
                    }
                }
                m_RedTeamColor = htmlColor;
                m_Setup.m_RedTeamText.color  = newColor;
                m_Setup.m_RedScoreText.color = newColor;
            }
        }
    }
Exemple #4
0
    // constructor - takes a Color
    public LABColor(Color col)
    {
        LABColor temp = FromColor(col);

        L = temp.l;
        A = temp.a;
        B = temp.b;
    }
    // constructor - takes a Color
    public LABColor(Color col)
    {
        LABColor temp = FromColor(col);

        L = temp.L;
        A = temp.A;
        B = temp.B;
    }
Exemple #6
0
        static double LABDistance(LABColor lab1, LABColor lab2)
        {
            var deltaL = lab1.l - lab2.l;
            var deltaA = lab1.a - lab2.a;
            var deltaB = lab1.b - lab2.b;

            return(Math.Sqrt(deltaA * deltaA + deltaB * deltaB + deltaL * deltaL));
        }
Exemple #7
0
    // constructor - takes a Color
    public LABColor(Color col) : this()
    {
        LABColor temp = FromColor(col);

        l = temp.l;
        a = temp.a;
        b = temp.b;
    }
Exemple #8
0
    //difference between two LABColors
    public static float[] Diff(LABColor color1, LABColor color2)
    {
        float[] diffArray = new float[3];
        diffArray [0] = color1.l - color2.l;
        diffArray [1] = color1.a - color2.a;
        diffArray [2] = color1.b - color2.b;

        return(diffArray);
    }
    //call SetColors AFTER sorting
    public void SetColors()
    {
        //count number of animals (sorted such that animal nodes come first)
        int seriesCount = seriesNodes.Count;
        int plantMax    = 7;
        int animalCount = 0;

        while (animalCount < seriesCount && seriesNodes [animalCount] > plantMax)
        {
            animalCount++;
        }
        int plantCount = seriesCount - animalCount;

        //get color range from LABColor for best spectrum (converts RGB to linear)
        //vary color from red for animals and from green for plants
        LABColor firstColor      = new LABColor(new Color(1.00f, 0.00f, 0.00f));
        LABColor lastAnimalColor = new LABColor(new Color(0.50f, 0.50f, 1.00f));                //incorporate blue
        LABColor firstPlantColor = new LABColor(new Color(0.50f, 0.50f, 0.00f));
        LABColor lastColor       = new LABColor(new Color(0.00f, 1.00f, 0.00f));

        float[] deltaAnimalColor = LABColor.Diff(lastAnimalColor, firstColor);
        for (int j = 0; j < deltaAnimalColor.Length; j++)
        {
            deltaAnimalColor[j] = deltaAnimalColor[j] / (Mathf.Max(1.0f, (float)animalCount - 1.0f));
        }
        if (plantCount == 1)
        {
            firstPlantColor = lastColor;
        }
        float[] deltaPlantColor = LABColor.Diff(lastColor, firstPlantColor);
        for (int j = 0; j < deltaPlantColor.Length; j++)
        {
            deltaPlantColor[j] = deltaPlantColor[j] / (Mathf.Max(1.0f, (float)plantCount - 1.0f));
        }
        LABColor currColor = firstColor;

        //loop through series to set series' colors
        for (int i = 0; i < seriesCount; i++)
        {
            if (i == animalCount)                 //first plant
            {
                currColor = firstPlantColor;
            }
            Color color = LABColor.ToColor(currColor);

            string name = seriesLabels [i];
            seriesColors [name]    = color;
            seriesColorsHex [name] = Functions.ColorToHex(color);

            currColor.Increment(i < animalCount ? deltaAnimalColor : deltaPlantColor);
        }
    }
Exemple #10
0
    public static double HSVDistanceCompare(Color e1, Color e2, int lever)
    {
        if (lever == 1)
        {
            float H1, S1, V1, H2, S2, V2;
            Color.RGBToHSV(e1, out H1, out S1, out V1);
            Color.RGBToHSV(e2, out H2, out S2, out V2);
            Vector3 x = new Vector3(H1, S1, V1);
            Vector3 y = new Vector3(H2, S2, V2);
            return(Vector3.Distance(x, y));
        }
        else
        {
            LABColor lab1 = LABColor.FromColor(e1);
            LABColor lab2 = LABColor.FromColor(e2);

            return(LABColor.Distance(lab1, lab2));
        }
    }
Exemple #11
0
    public void modifyMaterial(Dictionary <string, object> properties, Material[] materials)
    {
        string timeString    = UIDataManager.Instance.MonthKeys[UIDataManager.Instance.TimeIndex];
        string heightDataKey = UIDataManager.Instance.MonthKeys[UIDataManager.Instance.TimeIndex];
        string sideColorDataKey;

        if ((float.Parse(timeString.Substring(0, 4))) > 2005)
        {
            sideColorDataKey = "2010-minorityPercent";
        }
        else
        {
            sideColorDataKey = "2000-minorityPercent";
        }

        float minDataValue = 0;
        float maxDataValue = 100;

        float    dataValue    = minDataValue;
        Material sideMaterial = materials[1];

        if (properties.ContainsKey(sideColorDataKey) && properties.ContainsKey(heightDataKey))
        {
            if (float.TryParse(properties[sideColorDataKey].ToString(), out dataValue))
            {
                float    colorPercent      = (dataValue - minDataValue) / (maxDataValue - minDataValue);
                LABColor minColorVal       = new LABColor(0f, 25f, -100f);
                LABColor maxColorVal       = new LABColor(100f, 0f, 0f);
                LABColor sideMaterialColor = LABColor.Lerp(maxColorVal, minColorVal, colorPercent);
                sideMaterial.SetColor("_Color", sideMaterialColor.ToColor());
            }
        }
        else
        {
//			materials[0] = new Material(sideMaterial.shader);
//			// TODO: set top material to missing data material
//			materials[0].SetColor("_Color", new Color(229f / 255f, 117f / 255f, 52f / 255f, 1f));
//			materials [0].mainTexture = sideMaterial.mainTexture;
//			materials = new Material[0];
        }
    }
Exemple #12
0
 	public static Color ToColor(LABColor lab){
 		float D65x = 0.9505f;
 		float D65y = 1.0f;
 		float D65z = 1.0890f;
 		float delta = 6.0f/29.0f;
 		float fy = (lab.l+16f)/116.0f;
 		float fx = fy + (lab.a/500.0f);
 		float fz = fy - (lab.b/200.0f);
 		float x = (fx > delta)? D65x * (fx*fx*fx) : (fx - 16.0f/116.0f)*3f*(delta*delta)*D65x;
 		float y = (fy > delta)? D65y * (fy*fy*fy) : (fy - 16.0f/116.0f)*3f*(delta*delta)*D65y;
 		float z = (fz > delta)? D65z * (fz*fz*fz) : (fz - 16.0f/116.0f)*3f*(delta*delta)*D65z;
 		float r = x*3.2410f - y*1.5374f - z*0.4986f;
 		float g = -x*0.9692f + y*1.8760f - z*0.0416f;
 		float b = x*0.0556f - y*0.2040f + z*1.0570f;
 		r = (r<=0.0031308f)? 12.92f*r : (1f+0.055f)* Mathf.Pow(r, (1.0f/2.4f)) - 0.055f;
 		g = (g<=0.0031308f)? 12.92f*g : (1f+0.055f)* Mathf.Pow(g, (1.0f/2.4f)) - 0.055f;
 		b = (b<=0.0031308f)? 12.92f*b : (1f+0.055f)* Mathf.Pow(b, (1.0f/2.4f)) - 0.055f;
 		r = (r<0)? 0 : r;
 		g = (g<0)? 0 : g;
 		b = (b<0)? 0 : b;
 		return new Color(r, g, b);
 	}
Exemple #13
0
 // static function for linear interpolation between two LABColors
 public static LABColor Lerp(LABColor a, LABColor b, float t)
 {
     return(new LABColor(Mathf.Lerp(a.l, b.l, t), Mathf.Lerp(a.a, b.a, t), Mathf.Lerp(a.b, b.b, t)));
 }
Exemple #14
0
 // static function for interpolation between two Unity Colors through normalized colorspace
 public static Color Lerp(Color a, Color b, float t)
 {
     return((LABColor.Lerp(LABColor.FromColor(a), LABColor.FromColor(b), t)).ToColor());
 }
Exemple #15
0
    // Comparison
    public static float Compare(LABColor lab1, LABColor lab2)
    {
        //Set weighting factors to 1
        float k_L = 1.0f;
        float k_C = 1.0f;
        float k_H = 1.0f;

        //Calculate Cprime1, Cprime2, Cabbar
        float c_star_1_ab       = Mathf.Sqrt(lab1.A * lab1.A + lab1.B * lab1.B);
        float c_star_2_ab       = Mathf.Sqrt(lab2.A * lab2.A + lab2.B * lab2.B);
        float c_star_average_ab = (c_star_1_ab + c_star_2_ab) / 2;

        float c_star_average_ab_pot7 = c_star_average_ab * c_star_average_ab * c_star_average_ab;

        c_star_average_ab_pot7 *= c_star_average_ab_pot7 * c_star_average_ab;

        float G        = 0.5f * (1 - Mathf.Sqrt(c_star_average_ab_pot7 / (c_star_average_ab_pot7 + 6103515625)));   //25^7
        float a1_prime = (1 + G) * lab1.A;
        float a2_prime = (1 + G) * lab2.A;

        float C_prime_1 = Mathf.Sqrt(a1_prime * a1_prime + lab1.B * lab1.B);
        float C_prime_2 = Mathf.Sqrt(a2_prime * a2_prime + lab2.B * lab2.B);
        //Angles in Degree.
        float h_prime_1 = (Mathf.Rad2Deg * ((Mathf.Atan2(lab1.B, a1_prime)) + 360) % 360f);
        float h_prime_2 = (Mathf.Rad2Deg * ((Mathf.Atan2(lab2.B, a2_prime)) + 360) % 360f);

        float delta_L_prime = lab2.L - lab1.L;
        float delta_C_prime = C_prime_2 - C_prime_1;

        float h_bar = Mathf.Abs(h_prime_1 - h_prime_2);
        float delta_h_prime;

        if (C_prime_1 * C_prime_2 == 0)
        {
            delta_h_prime = 0;
        }
        else
        {
            if (h_bar <= 180f)
            {
                delta_h_prime = h_prime_2 - h_prime_1;
            }
            else if (h_bar > 180f && h_prime_2 <= h_prime_1)
            {
                delta_h_prime = h_prime_2 - h_prime_1 + 360f;
            }
            else
            {
                delta_h_prime = h_prime_2 - h_prime_1 - 360f;
            }
        }
        float delta_H_prime = 2 * Mathf.Sqrt(C_prime_1 * C_prime_2) * Mathf.Sin(Mathf.Deg2Rad * (delta_h_prime / 2));

        // Calculate CIEDE2000
        float L_prime_average = (lab1.L + lab2.L) / 2f;
        float C_prime_average = (C_prime_1 + C_prime_2) / 2f;

        //Calculate h_prime_average

        float h_prime_average;

        if (C_prime_1 * C_prime_2 == 0)
        {
            h_prime_average = 0;
        }
        else
        {
            if (h_bar <= 180f)
            {
                h_prime_average = (h_prime_1 + h_prime_2) / 2;
            }
            else if (h_bar > 180f && (h_prime_1 + h_prime_2) < 360f)
            {
                h_prime_average = (h_prime_1 + h_prime_2 + 360f) / 2;
            }
            else
            {
                h_prime_average = (h_prime_1 + h_prime_2 - 360f) / 2;
            }
        }
        float L_prime_average_minus_50_square = (L_prime_average - 50);

        L_prime_average_minus_50_square *= L_prime_average_minus_50_square;

        float S_L = 1 + ((.015f * L_prime_average_minus_50_square) / Mathf.Sqrt(20 + L_prime_average_minus_50_square));
        float S_C = 1 + .045f * C_prime_average;
        float T   = 1
                    - .17f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average - 30))
                    + .24f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 2))
                    + .32f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 3 + 6))
                    - .2f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 4 - 63));
        float S_H = 1 + .015f * T * C_prime_average;
        float h_prime_average_minus_275_div_25_square = (h_prime_average - 275) / (25);

        h_prime_average_minus_275_div_25_square *= h_prime_average_minus_275_div_25_square;
        float delta_theta = 30 * Mathf.Exp(-h_prime_average_minus_275_div_25_square);

        float C_prime_average_pot_7 = C_prime_average * C_prime_average * C_prime_average;

        C_prime_average_pot_7 *= C_prime_average_pot_7 * C_prime_average;
        float R_C = 2 * Mathf.Sqrt(C_prime_average_pot_7 / (C_prime_average_pot_7 + 6103515625));

        float R_T = -Mathf.Sin(Mathf.Deg2Rad * ((2 * delta_theta))) * R_C;

        float delta_L_prime_div_k_L_S_L = delta_L_prime / (S_L * k_L);
        float delta_C_prime_div_k_C_S_C = delta_C_prime / (S_C * k_C);
        float delta_H_prime_div_k_H_S_H = delta_H_prime / (S_H * k_H);

        float CIEDE2000 = Mathf.Sqrt(
            delta_L_prime_div_k_L_S_L * delta_L_prime_div_k_L_S_L
            + delta_C_prime_div_k_C_S_C * delta_C_prime_div_k_C_S_C
            + delta_H_prime_div_k_H_S_H * delta_H_prime_div_k_H_S_H
            + R_T * delta_C_prime_div_k_C_S_C * delta_H_prime_div_k_H_S_H
            );

        return(CIEDE2000);
    }
Exemple #16
0
        SKColor colorQuantify(SKColor c)
        {
            LABColor l = ToLAB(c);

            return(LAB2RGB[LABMap.OrderBy((x) => LABDistance(x, l)).First()]);
        }
    //call SetColors AFTER sorting
    public void SetColors()
    {
        //count number of animals (sorted such that animal nodes come first)
        int seriesCount = seriesNodes.Count;
        int plantMax = 7;
        int animalCount = 0;
        while (animalCount < seriesCount && seriesNodes [animalCount] > plantMax) {
            animalCount ++;
        }
        int plantCount = seriesCount - animalCount;

        //get color range from LABColor for best spectrum (converts RGB to linear)
        //vary color from red for animals and from green for plants
        LABColor firstColor = 		new LABColor (new Color (1.00f, 0.00f, 0.00f));
        LABColor lastAnimalColor =	new LABColor (new Color (0.50f, 0.50f, 1.00f)); //incorporate blue
        LABColor firstPlantColor = 	new LABColor (new Color (0.50f, 0.50f, 0.00f));
        LABColor lastColor = 		new LABColor (new Color (0.00f, 1.00f, 0.00f));
        float[] deltaAnimalColor = LABColor.Diff (lastAnimalColor, firstColor);
        for (int j=0; j < deltaAnimalColor.Length; j++) {
            deltaAnimalColor[j] = deltaAnimalColor[j] / (Mathf.Max(1.0f, (float)animalCount - 1.0f));
        }
        if (plantCount == 1) {
            firstPlantColor = lastColor;
        }
        float[] deltaPlantColor = LABColor.Diff (lastColor, firstPlantColor);
        for (int j=0; j < deltaPlantColor.Length; j++) {
            deltaPlantColor[j] = deltaPlantColor[j] / (Mathf.Max(1.0f, (float)plantCount - 1.0f));
        }
        LABColor currColor = firstColor;

        //loop through series to set series' colors
        for (int i = 0; i < seriesCount; i ++) {
            if (i == animalCount ) {  //first plant
                currColor = firstPlantColor;
            }
            Color color = LABColor.ToColor (currColor);

            string name = seriesLabels [i];
            seriesColors [name] = color;
            seriesColorsHex [name] = Functions.ColorToHex (color);

            currColor.Increment(i < animalCount ? deltaAnimalColor : deltaPlantColor);
        }
    }
Exemple #18
0
 // function for converting an instance of LABColor to Color
 public Color ToColor()
 {
     return(LABColor.ToColor(this));
 }
Exemple #19
0
 public static Color AverageColorsLAB(Color a, Color b)
 {
     return(LABColor.Lerp(a, b, 0.5f));
 }
        // https://en.wikipedia.org/wiki/Color_difference
        public static float GetDifference(this Color a, Color b)
        {
            var lab1 = LABColor.ToLABColor(a);
            var lab2 = LABColor.ToLABColor(b);

            var c_star_1_ab       = Mathf.Sqrt(lab1.A * lab1.A + lab1.B * lab1.B);
            var c_star_2_ab       = Mathf.Sqrt(lab2.A * lab2.A + lab2.B * lab2.B);
            var c_star_average_ab = (c_star_1_ab + c_star_2_ab) * 0.5f;

            var c_star_average_ab_pot7 = c_star_average_ab * c_star_average_ab * c_star_average_ab;

            c_star_average_ab_pot7 *= c_star_average_ab_pot7 * c_star_average_ab;

            var G        = 0.5f * (1.0f - Mathf.Sqrt(c_star_average_ab_pot7 / (c_star_average_ab_pot7 + 6103515625f))); // 25^7
            var a1_prime = (1.0f + G) * lab1.A;
            var a2_prime = (1.0f + G) * lab2.A;

            var C_prime_1 = Mathf.Sqrt(a1_prime * a1_prime + lab1.B * lab1.B);
            var C_prime_2 = Mathf.Sqrt(a2_prime * a2_prime + lab2.B * lab2.B);

            var h_prime_1 = (Mathf.Atan2(lab1.B, a1_prime) * 180.0f / Mathf.PI + 360.0f) % 360.0f;
            var h_prime_2 = (Mathf.Atan2(lab2.B, a2_prime) * 180.0f / Mathf.PI + 360.0f) % 360.0f;

            var delta_L_prime = lab2.L - lab1.L;
            var delta_C_prime = C_prime_2 - C_prime_1;

            var   h_bar = Mathf.Abs(h_prime_1 - h_prime_2);
            float delta_h_prime;

            if (C_prime_1 * C_prime_2 == 0.0f)
            {
                delta_h_prime = 0.0f;
            }
            else
            {
                if (h_bar <= 180.0f)
                {
                    delta_h_prime = h_prime_2 - h_prime_1;
                }
                else if (h_bar > 180.0f && h_prime_2 <= h_prime_1)
                {
                    delta_h_prime = h_prime_2 - h_prime_1 + 360.0f;
                }
                else
                {
                    delta_h_prime = h_prime_2 - h_prime_1 - 360.0f;
                }
            }

            var delta_H_prime = 2.0f * Mathf.Sqrt(C_prime_1 * C_prime_2) * Mathf.Sin(delta_h_prime * Mathf.PI / 360.0f);

            var L_prime_average = (lab1.L + lab2.L) * 0.5f;
            var C_prime_average = (C_prime_1 + C_prime_2) * 0.5f;

            float h_prime_average;

            if (C_prime_1 * C_prime_2 == 0.0f)
            {
                h_prime_average = 0.0f;
            }
            else
            {
                if (h_bar <= 180.0f)
                {
                    h_prime_average = (h_prime_1 + h_prime_2) * 0.5f;
                }
                else if (h_bar > 180.0f && h_prime_1 + h_prime_2 < 360.0f)
                {
                    h_prime_average = (h_prime_1 + h_prime_2 + 360.0f) * 0.5f;
                }
                else
                {
                    h_prime_average = (h_prime_1 + h_prime_2 - 360.0f) * 0.5f;
                }
            }

            var L_prime_average_minus_50_square = L_prime_average - 50.0f;

            L_prime_average_minus_50_square *= L_prime_average_minus_50_square;

            var S_L = 1.0f + 0.015f * L_prime_average_minus_50_square / Mathf.Sqrt(20.0f + L_prime_average_minus_50_square);
            var S_C = 1.0f + 0.045f * C_prime_average;
            var T   = 1.0f
                      - 0.17f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average - 30.0f))
                      + 0.24f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 2.0f))
                      + 0.32f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 3.0f + 6.0f))
                      - 0.2f * Mathf.Cos(Mathf.Deg2Rad * (h_prime_average * 4.0f - 63.0f));
            var S_H = 1.0f + 0.015f * T * C_prime_average;
            var h_prime_average_minus_275_div_25_square = (h_prime_average - 275.0f) / 25.0f;

            h_prime_average_minus_275_div_25_square *= h_prime_average_minus_275_div_25_square;
            var delta_theta = 30.0f * Mathf.Exp(-h_prime_average_minus_275_div_25_square);

            var C_prime_average_pot_7 = C_prime_average * C_prime_average * C_prime_average;

            C_prime_average_pot_7 *= C_prime_average_pot_7 * C_prime_average;

            var R_C = 2.0f * Mathf.Sqrt(C_prime_average_pot_7 / (C_prime_average_pot_7 + 6103515625f));
            var R_T = -Mathf.Sin(Mathf.Deg2Rad * (2.0f * delta_theta)) * R_C;

            var delta_L_prime_div_k_L_S_L = delta_L_prime / S_L;
            var delta_C_prime_div_k_C_S_C = delta_C_prime / S_C;
            var delta_H_prime_div_k_H_S_H = delta_H_prime / S_H;

            return(Mathf.Sqrt(delta_L_prime_div_k_L_S_L * delta_L_prime_div_k_L_S_L
                              + delta_C_prime_div_k_C_S_C * delta_C_prime_div_k_C_S_C
                              + delta_H_prime_div_k_H_S_H * delta_H_prime_div_k_H_S_H
                              + R_T * delta_C_prime_div_k_C_S_C * delta_H_prime_div_k_H_S_H));
        }
 // static function for returning the color difference in a normalized colorspace (Delta-E)
 public static float Distance(LABColor a, LABColor b)
 {
     return Mathf.Sqrt(Mathf.Pow((a.l - b.l), 2f) + Mathf.Pow((a.a - b.a), 2f) + Mathf.Pow((a.b - b.b),2f));
 }
 // static function for converting from Color to LABColor
 public static LABColor FromColor(Color c)
 {
     float D65x = 0.9505f;
     float D65y = 1.0f;
     float D65z = 1.0890f;
     float rLinear = c.r;
     float gLinear = c.g;
     float bLinear = c.b;
     float r = (rLinear > 0.04045f)? Mathf.Pow((rLinear + 0.055f)/(1f + 0.055f), 2.2f) : (rLinear/12.92f) ;
     float g = (gLinear > 0.04045f)? Mathf.Pow((gLinear + 0.055f)/(1f + 0.055f), 2.2f) : (gLinear/12.92f) ;
     float b = (bLinear > 0.04045f)? Mathf.Pow((bLinear + 0.055f)/(1f + 0.055f), 2.2f) : (bLinear/12.92f) ;
     float x = (r*0.4124f + g*0.3576f + b*0.1805f);
     float y = (r*0.2126f + g*0.7152f + b*0.0722f);
     float z = (r*0.0193f + g*0.1192f + b*0.9505f);
     x = (x>0.9505f)? 0.9505f : ((x<0f)? 0f : x);
     y = (y>1.0f)? 1.0f : ((y<0f)? 0f : y);
     z = (z>1.089f)? 1.089f : ((z<0f)? 0f : z);
     LABColor lab = new LABColor(0f,0f,0f);
     float fx = x/D65x;
     float fy = y/D65y;
     float fz = z/D65z;
     fx = ((fx > 0.008856f)? Mathf.Pow(fx, (1.0f/3.0f)) : (7.787f*fx + 16.0f/116.0f));
     fy = ((fy > 0.008856f)? Mathf.Pow(fy, (1.0f/3.0f)) : (7.787f*fy + 16.0f/116.0f));
     fz = ((fz > 0.008856f)? Mathf.Pow(fz, (1.0f/3.0f)) : (7.787f*fz + 16.0f/116.0f));
     lab.l = 116.0f * fy - 16f;
     lab.a = 500.0f * (fx - fy);
     lab.b = 200.0f * (fy - fz);
     return lab;
 }
 // static function for converting from LABColor to Color
 public static Color ToColor(LABColor lab)
 {
     float D65x = 0.9505f;
     float D65y = 1.0f;
     float D65z = 1.0890f;
     float delta = 6.0f/29.0f;
     float fy = (lab.l+16f)/116.0f;
     float fx = fy + (lab.a/500.0f);
     float fz = fy - (lab.b/200.0f);
     float x = (fx > delta)? D65x * (fx*fx*fx) : (fx - 16.0f/116.0f)*3f*(delta*delta)*D65x;
     float y = (fy > delta)? D65y * (fy*fy*fy) : (fy - 16.0f/116.0f)*3f*(delta*delta)*D65y;
     float z = (fz > delta)? D65z * (fz*fz*fz) : (fz - 16.0f/116.0f)*3f*(delta*delta)*D65z;
     float r = x*3.2410f - y*1.5374f - z*0.4986f;
     float g = -x*0.9692f + y*1.8760f - z*0.0416f;
     float b = x*0.0556f - y*0.2040f + z*1.0570f;
     r = (r<=0.0031308f)? 12.92f*r : (1f+0.055f)* Mathf.Pow(r, (1.0f/2.4f)) - 0.055f;
     g = (g<=0.0031308f)? 12.92f*g : (1f+0.055f)* Mathf.Pow(g, (1.0f/2.4f)) - 0.055f;
     b = (b<=0.0031308f)? 12.92f*b : (1f+0.055f)* Mathf.Pow(b, (1.0f/2.4f)) - 0.055f;
     r = (r<0)? 0 : r;
     g = (g<0)? 0 : g;
     b = (b<0)? 0 : b;
     return new Color(r, g, b);
 }
Exemple #24
0
 public static Color LerpColorsLAB(Color a, Color b, float t)
 {
     return(LABColor.Lerp(a, b, t));
 }
Exemple #25
0
 // static function for returning the color difference in a normalized colorspace (Delta-E)
 public static float Distance(LABColor a, LABColor b)
 {
     return(Mathf.Sqrt(Mathf.Pow((a.l - b.l), 2f) + Mathf.Pow((a.a - b.a), 2f) + Mathf.Pow((a.b - b.b), 2f)));
 }
 // static function for linear interpolation between two LABColors
 public static LABColor Lerp(LABColor a, LABColor b, float t)
 {
     return(new LABColor(Mathf.Lerp(a.L, b.L, t), Mathf.Lerp(a.A, b.A, t), Mathf.Lerp(a.B, b.B, t)));
 }
 // static function for returning the color difference in a normalized colorspace (Delta-E)
 public static float Distance(LABColor a, LABColor b)
 {
     return(Mathf.Sqrt(Mathf.Pow((a.L - b.L), 2f) + Mathf.Pow((a.A - b.A), 2f) + Mathf.Pow((a.B - b.B), 2f)));
 }
 // static function for linear interpolation between two LABColors
 public static LABColor Lerp(LABColor a, LABColor b, float t)
 {
     return new LABColor(Mathf.Lerp(a.l, b.l, t), Mathf.Lerp(a.a, b.a, t), Mathf.Lerp(a.b, b.b, t));
 }
    //difference between two LABColors
    public static float[] Diff(LABColor color1, LABColor color2)
    {
        float[] diffArray = new float[3];
        diffArray [0] = color1.l - color2.l;
        diffArray [1] = color1.a - color2.a;
        diffArray [2] = color1.b - color2.b;

        return diffArray;
    }