How to calculate a mixture of 4 colors defined in the CIELAB L * a * b * model?

I have 4 colors that I converted from RGB to the CIELAB L * a * b * model .

  • How can I calculate the blending of these four colors when I have (L,a,b)for each such color?

  • How can I calculate the same mix if I want to put the scales (w1, w2, w3, w4)on these 4 colors, having 1 maximum and 0 minimum (no) weight?

+5
source share
2 answers

Assuming you have a structure like this:

typedef struct LabColor {
    uint8_t L;
    uint8_t a;
    uint8_t b;
} LabColor;

and an array of 4 of them:

LabColor colors[4];
getMeSomeColors (colors);

and weight:

float weights[4];
getMeSomeWeights (weights);

One possible way to mix is ​​as follows:

float LSum = 0.0;
float aSum = 0.0;
float bSum = 0.0;
float weightSum = 0.0;
for (int i = 0; i < 4; i++)
{
    LSum += ((float)colors [ i ].L * weights [ i ]);
    aSum += ((float)colors [ i ].a * weights [ i ]);
    bSum += ((float)colors [ i ].b * weights [ i ]);
    weightSum += weights[i];
}
LabColor result;
result.L = (uint8_t)(LSum / weightSum);
result.a = (uint8_t)((aSum / weightSum) + 127);
result.b = (uint8_t)((bSum / weightSum) + 127);

, 0 1. , . 1, .

. , , , .

+10

L*a*b* ( -) RGB, . .

L*a*b* , .

+5

All Articles