C计算CIELAB、CIELUV均匀颜色空间中两种颜色的色差
作者:互联网
C计算CIELAB、CIELUV均匀颜色空间中两种颜色的色差
** 如何利用C语言计算两种颜色在CIELAB、CIELUV的总色差?例如:已知两颜色样品的色度值为:Y1=76.79,x1=0.4480, y1=0.3478;Y2=75.67,x2=0.4621,y2=0.4090 试按照2°视场和D50光源计算两颜色的总色差 和(如果需要计算其他颜色的色差,只需要修改代码9、10行的初始值)直接给大家上源代码(vs2017):**
#include<stdio.h>
#include<math.h>
double Luv_vv(double X, double Y, double Z);//计算u’
double Luv_uu(double X, double Y, double Z);//计算v’
double cijizhiX(double x, double y, double Y);//计算X
double cijizhiZ(double z, double y, double Y);//计算Y
int main()
{
double Y1 = 76.79, X1 = 0, Z1 = 0, x1 = 0.4480, y1 = 0.3478, z1 = 0, L1, a1, b1, uu1, vv1, u1, v1;//颜色1初始值
double Y2 = 75.67, X2 = 0, Z2 = 0, x2 = 0.4621, y2 = 0.4090, z2 = 0, L2, a2, b2, uu2, vv2, u2, v2;//颜色2初始值
double Y0 = 100, X0 = 96.42, Z0 = 82.51, uu0 = 0.20916, vv0 = 0.48808;//D50初始值
double Eab = 0, Euv = 0;
/*******************基本量的计算*****************/
z1 = 1 - x1 - y1;
z2 = 1 - x2 - y2;
X1 = cijizhiX(x1, y1, Y1); Z1 = cijizhiZ(z1, y1, Y1);
X2 = cijizhiX(x2, y2, Y2); Z2 = cijizhiZ(z2, y2, Y2);
uu1 = Luv_uu(X1, Y1, Z1); uu2 = Luv_uu(X2, Y2, Z2);
vv1 = Luv_vv(X1, Y1, Z1); vv2 = Luv_vv(X2, Y2, Z2);
printf("X1=%f,Y1=%f,Z1=%f,X2=%f,Y2=%f,Z2=%f\n\n", X1, Y1, Z1, X2, Y2, Z2);
/***********************颜色1************************/
L1 = 116 * pow(Y1 / Y0, 1.0 / 3) - 16;
a1 = 500 * (pow(X1 / X0, 1.0 / 3) - pow(Y1 / Y0, 1.0 / 3));
b1 = 200 * (pow(Y1 / Y0, 1.0 / 3) - pow(Z1 / Z0, 1.0 / 3));
u1 = 13 * L1*(uu1 - uu0);
v1 = 13 * L1*(vv1 - vv0);
printf("L1=%f,a1=%f,b1=%f,u1=%f,v1=%f\n\n", L1, a1, b1, u1, v1);
/********************颜色2*********************/
L2 = 116 * pow(Y2 / Y0, 1.0 / 3) - 16;
a2 = 500 * (pow(X2 / X0, 1.0 / 3) - pow(Y2 / Y0, 1.0 / 3));
b2 = 200 * (pow(Y2 / Y0, 1.0 / 3) - pow(Z2 / Z0, 1.0 / 3));
u2 = 13 * L2*(uu2 - uu0);
v2 = 13 * L2*(vv2 - vv0);
printf("L2=%f,a2=%f,b2=%f,u2=%f,v2=%f\n\n", L2, a2, b2, u2, v2);
/*********************总色差*************************/
Eab = sqrt(pow(L1 - L2, 2) + pow(a1 - a2, 2) + pow(b1 - b2, 2));
Euv = sqrt(pow(L1 - L2, 2) + pow(u1 - u2, 2) + pow(v1 - v2, 2));
printf("总色差Eab=%lf\n总色差Euv=%lf\n\n", Eab, Euv);
return 0;
}
double cijizhiX(double x,double y,double Y)
{
return x * Y / y;
}
double cijizhiZ(double z, double y, double Y)
{
return z * Y / y;
}
double Luv_uu(double X, double Y, double Z)//计算u'
{
double uu;
return uu = 4 * X / (X + 15 * Y + 3 * Z);
}
double Luv_vv(double X, double Y, double Z)//计算v'
{
double vv;
return vv = 9 * Y / (X + 15 * Y + 3 * Z)
运行结果如下:(结果正确)
标签:CIELUV,Luv,pow,double,Y1,颜色,1.0,Y2,CIELAB 来源: https://blog.csdn.net/qq_45160840/article/details/105973303