最近在做一个关于颜料的项目,其中涉及到LAB转RGB,
这是一个涉及到几条算法的项目,老板见我是新人,以为我做不出来,然后我不服,
经过一天的了解加上代码量也不多,最后一天时间就完成了,下面分享一下,不过写的不好,不要见怪
[Java] 纯文本查看 复制代码
Double L =pfgl.getPfglLabl();
Double A =pfgl.getPfglLaba();
Double B =pfgl.getPfglLabb();
Double YY =(L+16)/116;
Double XX =(L+16)/116+A/500;
Double ZZ =(L+16)/116-B/200;
/* double Xn = 94.83;
double Yn = 100.0;
double Zn = 107.38; */
double Xn = 94.83;
double Yn = 100.0;
double Zn = 107.38;
/* double o =6;
double p =29;*/
Double D = Double.valueOf(0.206893);
double Y = 0;
double X = 0;
double Z = 0;
if (YY>D){
Y = Yn * Math.pow(YY,3.0);
}
else {
double C = 7.787;
double G = Double.valueOf(0.13793103448275862);
Y = Yn * (YY - G) / C;
}
if (XX>D){
X = Xn * Math.pow(XX,3.0);
}
else {
double C = 7.787;
double G = Double.valueOf(0.13793103448275862);
X = Xn * (XX - G) / C;
}
if (ZZ>D){
Z = Zn * Math.pow(ZZ,3.0);
}
else {
double C = 7.787;
double G = Double.valueOf(0.13793103448275862);
Z =Zn * (ZZ - G) / C;
}
//X, Y and Z input refer to a D65/2° standard illuminant.
//sR, sG and sB (standard RGB) output range = 0 ÷ 255
/* Double var_X;
Double var_Y;
Double var_Z; */
Double var_X = X * 242.36628;
Double var_Y = Y * 255;
Double var_Z = Z * 277.63227;
Double var_R;
Double var_G;
Double var_B;
var_X = X / 100;
var_Y = Y / 100;
var_Z = Z / 100;
var_R = var_X * 3.2406 + var_Y * -1.5372 + var_Z * -0.4986;
var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * 0.0415;
var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570;
/* var_R = var_X * 0.412453 + var_Y * 0.357580 + var_Z * 0.180423;
var_G = var_X * 0.212671 + var_Y * 0.715160 + var_Z * 0.072169;
var_B = var_X * 0.019334 + var_Y * 0.119193 + var_Z * 0.950227;*/
if ( var_R > 0.0031308 ) var_R = 1.055 * ( Math.pow(var_R , ( 1 / 2.4 )) ) - 0.055;
else var_R = 12.92 * var_R;
if ( var_G > 0.0031308 ) var_G = 1.055 * ( Math.pow(var_G , ( 1 / 2.4 )) ) - 0.055;
else var_G = 12.92 * var_G;
if ( var_B > 0.0031308 ) var_B = 1.055 * ( Math.pow(var_B , ( 1 / 2.4 )) ) - 0.055;
else var_B = 12.92 * var_B;
/* double sR = var_R * 255.0;
double sG = var_G * 255.0;
double sB = var_B * 255.0;*/
Integer sR = (int) Math.round(var_R * 255) ;
Integer sG = (int) Math.round(var_G * 255) ;
Integer sB = (int) Math.round(var_B * 255) ;
Integer cR;
Integer cG;
Integer cB;
cR = sR >= 255 ? 255 : sR;
cG = sG >= 255 ? 255 : sG;
cB = sB >= 255 ? 255 : sB;
cR = sR < 0 ? 0 : sR;
cG = sG < 0 ? 0 : sG;
cB = sB < 0 ? 0 : sB;
String DOU = "RGB"+"("+ cR + "," + cG + "," + cB +")";
pfgl.setPfglYs(DOU);
有最近学习算法的各位,可以带我一下,本人后端新人小子一个 |