AnLab颜色空间中颜色之间的距离

时间:2016-01-18 18:28:51

标签: c++ colors color-space

我想编写一个程序来计算 AnLab 颜色空间中 deltaE (颜色之间的距离)。

公式在这里:Click Here,其中deltaVy是亮度坐标和delta(Vx-Vy)之差,delta(Vz-Vy)是颜色坐标之间的差异。

所以,
1.如何计算deltaVx,deltaVy,deltaVz?
也许某人有关于这个色彩空间的更多信息。我将不胜感激。

到目前为止,我从RGB到XYZ进行了计算,但却陷入deltaVx,Vy,Vz计算中。

修改
经过一番搜索,我发现deltaVx,Vy,Vz来自于向XYZ添加收缩坐标。但经过所有计算后,我不知道为什么距离是错误的(非常大的价值)。我也编辑了我的代码,现在它已经实现了公式。同样出于测试目的,我已经使用非常相似的颜色(现在deltaE应该是小值,但是有些错误)。

到目前为止编辑的代码:

#include <iostream>
#include <math.h>
using namespace std;

class colorRGB
{
public:
    double R1, G1, B1;  // RGB colors
    double X, Y, Z; // vectors
    double Vx, Vy, Vz;
    double L, a, b;
    colorRGB(double R, double G, double B) //Make new color
    {
        this->R1 = R;
        this->G1 = G;
        this->B1 = B;   
    } 
    void wypisz()
    {
        cout << "X: " << X << " " << "Y: " << Y << " " << "Z: " << Z << endl;
        cout << "Vx: " << Vx << " Vy: " << Vy << " Vz: " << Vz << endl;
        cout << "L: " << L << " a: " << a << " b: " << b << endl;
        cout << "--------------------------------------------------------------" << endl;
    }
    void calcLab(double pVx, double pVy, double pVz) // calulate L*ab
    {
        L = 9.2*(pVy);
        a = 40 * (pVx - pVy);
        b = 16 * (pVy - pVz);
    }
    void RGBtoXYZ()
    {
        double R = R1 / 255; // R from 0 to 255 etc.
        double G = G1 / 255; 
        double B = B1 / 255;

        if (R > 0.04045) { // R to X
            R = (R + 0.055) / 1.055;
            R = pow(R, 2.4);
        }
        else R = R / 12.92;

        if (G > 0.04045) { // G to Y
            G = (G + 0.055) / 1.055;
            G = pow(G, 2.4);
        }
        else   G = G / 12.92;

        if (B > 0.04045) { // B to Z
            B = (B + 0.055) / 1.055;
            B = pow(B, 2.4);
        }
        else B = B / 12.92;

        R = R * 100;
        G = G * 100;
        B = B * 100;

        //Illuminant = D65
        X = (R * 0.4124) + (G * 0.3576) + (B * 0.1805);
        Y = (R * 0.2126) + (G * 0.7152) + (B * 0.0722);
        Z = (R * 0.0193) + (G * 0.1192) + (B * 0.9505);

        X = X - Y; // subtract from X and Z (prepare variables to further calculations)
        Z = Z - Y;

        Vx = X + 0.4124 + 0.3576 + 0.1805; // add shrinking coordinates
        Vy = Y + 0.2126 + 0.7152 + 0.0722;
        Vz = Z + 0.0193 + 0.1192 + 0.9505;

        calcLab(Vx, Vy, Vz); 

    }
};

void calcDeltaVar(colorRGB *color1, colorRGB *color2) {
    int x = 0;
    double dE;
    double ins;
    double dVy = color1->Vy - color2->Vy;
    double dVxVy = color1->Vx - color2->Vy;
    double dVzVy = color1->Vz - color2->Vy;

    ins = 0.23*(pow(dVy, 2)) + pow(dVxVy, 2) + 0.4*(pow(dVzVy, 2));
    dE = 40 * (sqrt(ins));
    x++;
    cout << "Delta Ean for pair " << x << " is: " << dE << endl;

};



int main()
{
    colorRGB rgb(255.0, 255.0, 255.0);
    colorRGB rgb1(254.0, 254.0, 254.0);

    rgb.RGBtoXYZ();
    rgb.wypisz();

    rgb1.RGBtoXYZ();
    rgb1.wypisz();

    calcDeltaVar(&rgb, &rgb1);
    return 0;
}

提前致谢:)

0 个答案:

没有答案