Itcwb : cleanup and speedup, #5676
This commit is contained in:
parent
96ab9863dd
commit
be5e447f53
@ -3210,8 +3210,8 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul,
|
|||||||
//calculate spectral data for blackbody at temp!
|
//calculate spectral data for blackbody at temp!
|
||||||
double ColorTemp::blackbody_spect(double wavelength, double temperature)
|
double ColorTemp::blackbody_spect(double wavelength, double temperature)
|
||||||
{
|
{
|
||||||
double wlm = wavelength * 1e-9; /* Wavelength in meters */
|
const double wlm = wavelength * 1e-9; /* Wavelength in meters */
|
||||||
return (3.7417715247e-16 / pow(wlm, 5)) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light
|
return (3.7417715247e-16 / (wlm * rtengine::pow4(wlm))) / //3.7417..= c1 = 2*Pi*h*c2 where h=Planck constant, c=velocity of light
|
||||||
(xexp(1.438786e-2 / (wlm * temperature)) - 1.0); //1.4387..= c2 = h*c/k where k=Boltzmann constant
|
(xexp(1.438786e-2 / (wlm * temperature)) - 1.0); //1.4387..= c2 = h*c/k where k=Boltzmann constant
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3337,62 +3337,38 @@ void ColorTemp::spectrum_to_color_xyz_preset(const double* spec_color, const dou
|
|||||||
void ColorTemp::spectrum_to_color_xyz_daylight(const double* spec_color, double _m1, double _m2, double &xx, double &yy, double &zz)
|
void ColorTemp::spectrum_to_color_xyz_daylight(const double* spec_color, double _m1, double _m2, double &xx, double &yy, double &zz)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double lambda, X = 0, Y = 0, Z = 0, Yo = 0;
|
double lambda, X = 0, Y = 0, Z = 0;
|
||||||
|
|
||||||
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
||||||
|
const double Me = spec_color[i];
|
||||||
double Me;
|
const double Mc = daylight_spect(lambda, _m1, _m2);
|
||||||
double Mc;
|
|
||||||
|
|
||||||
Me = get_spectral_color(lambda, spec_color);
|
|
||||||
Mc = daylight_spect(lambda, _m1, _m2);
|
|
||||||
X += Mc * cie_colour_match_jd[i][0] * Me;
|
X += Mc * cie_colour_match_jd[i][0] * Me;
|
||||||
Y += Mc * cie_colour_match_jd[i][1] * Me;
|
Y += Mc * cie_colour_match_jd[i][1] * Me;
|
||||||
Z += Mc * cie_colour_match_jd[i][2] * Me;
|
Z += Mc * cie_colour_match_jd[i][2] * Me;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
xx = X / Y;
|
||||||
|
yy = 1.0;
|
||||||
double Ms;
|
zz = Z / Y;
|
||||||
|
|
||||||
Ms = daylight_spect(lambda, _m1, _m2);
|
|
||||||
Yo += cie_colour_match_jd[i][1] * Ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
xx = X / Yo;
|
|
||||||
yy = Y / Yo;
|
|
||||||
zz = Z / Yo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate XYZ from spectrum data (color) and illuminant : J.Desmis december 2011
|
//calculate XYZ from spectrum data (color) and illuminant : J.Desmis december 2011
|
||||||
void ColorTemp::spectrum_to_color_xyz_blackbody(const double* spec_color, double _temp, double &xx, double &yy, double &zz)
|
void ColorTemp::spectrum_to_color_xyz_blackbody(const double* spec_color, double _temp, double &xx, double &yy, double &zz)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double lambda, X = 0, Y = 0, Z = 0, Yo = 0;
|
double lambda, X = 0, Y = 0, Z = 0;
|
||||||
|
|
||||||
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
||||||
|
const double Me = spec_color[i];
|
||||||
double Me;
|
const double Mc = blackbody_spect(lambda, _temp);
|
||||||
double Mc;
|
|
||||||
|
|
||||||
Me = get_spectral_color(lambda, spec_color);
|
|
||||||
Mc = blackbody_spect(lambda, _temp);
|
|
||||||
X += Mc * cie_colour_match_jd[i][0] * Me;
|
X += Mc * cie_colour_match_jd[i][0] * Me;
|
||||||
Y += Mc * cie_colour_match_jd[i][1] * Me;
|
Y += Mc * cie_colour_match_jd[i][1] * Me;
|
||||||
Z += Mc * cie_colour_match_jd[i][2] * Me;
|
Z += Mc * cie_colour_match_jd[i][2] * Me;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, lambda = 350; lambda < 830.1; i++, lambda += 5) {
|
xx = X / Y;
|
||||||
|
yy = 1.0;
|
||||||
double Ms;
|
zz = Z / Y;
|
||||||
|
|
||||||
Ms = blackbody_spect(lambda, _temp);
|
|
||||||
Yo += cie_colour_match_jd[i][1] * Ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
xx = X / Yo;
|
|
||||||
yy = Y / Yo;
|
|
||||||
zz = Z / Yo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double ColorTemp::daylight_spect(double wavelength, double m1, double m2)
|
double ColorTemp::daylight_spect(double wavelength, double m1, double m2)
|
||||||
@ -3483,7 +3459,7 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa
|
|||||||
double ZZ;
|
double ZZ;
|
||||||
} WbTxyz;
|
} WbTxyz;
|
||||||
//probbaly can be "passed" with rawimagesource.cc but I don't know how to do.
|
//probbaly can be "passed" with rawimagesource.cc but I don't know how to do.
|
||||||
WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after
|
constexpr WbTxyz Txyz[118] = {//temperature Xwb Zwb 118 values x wb and y wb are calculated after
|
||||||
{2001., 1.273842, 0.145295},
|
{2001., 1.273842, 0.145295},
|
||||||
{2101., 1.244008, 0.167533},
|
{2101., 1.244008, 0.167533},
|
||||||
{2201., 1.217338, 0.190697},
|
{2201., 1.217338, 0.190697},
|
||||||
@ -3612,68 +3588,22 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa
|
|||||||
double Zref;
|
double Zref;
|
||||||
} XYZref;
|
} XYZref;
|
||||||
XYZref Refxyz[N_c + 1];
|
XYZref Refxyz[N_c + 1];
|
||||||
typedef struct XYZrefcat02 {
|
|
||||||
double Xrefcat;
|
|
||||||
double Yrefcat;
|
|
||||||
double Zrefcat;
|
|
||||||
} XYZrefcat02;
|
|
||||||
XYZrefcat02 Refxyzcat02[N_c + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
Refxyz[i].Xref = 0.f;
|
Refxyz[i].Xref = 0.f;
|
||||||
Refxyz[i].Yref = 0.f;
|
Refxyz[i].Yref = 0.f;
|
||||||
Refxyz[i].Zref = 0.f;
|
Refxyz[i].Zref = 0.f;
|
||||||
Refxyzcat02[i].Xrefcat = 0.f;
|
|
||||||
Refxyzcat02[i].Yrefcat = 0.f;
|
|
||||||
Refxyzcat02[i].Zrefcat = 0.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct chrom {
|
|
||||||
float chroab;
|
|
||||||
float chroa;
|
|
||||||
float chrob;
|
|
||||||
int nn;
|
|
||||||
float L;
|
|
||||||
bool operator()(const chrom& lchro, const chrom& rchro)
|
|
||||||
{
|
|
||||||
return lchro.chroab < rchro.chroab;
|
|
||||||
}
|
|
||||||
|
|
||||||
} ;
|
|
||||||
|
|
||||||
// chrom wbchro[N_c + 1];
|
|
||||||
|
|
||||||
double tempw = 5000.;
|
double tempw = 5000.;
|
||||||
|
|
||||||
if (separated) {
|
if (separated) {
|
||||||
tempw = Txyz[repref].Tem;
|
tempw = Txyz[repref].Tem;
|
||||||
// tempw = 5004.;
|
|
||||||
|
|
||||||
if (tempw <= INITIALBLACKBODY) {
|
if (tempw <= INITIALBLACKBODY) {
|
||||||
// float aa = 0.f;
|
|
||||||
// float bb = 0.f;
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, TX[i], TY[i], TZ[i]);
|
spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, TX[i], TY[i], TZ[i]);
|
||||||
/* float XX = TX[i] * 65535.f;
|
|
||||||
float YY = TY[i] * 65535.f;
|
|
||||||
float ZZ = TZ[i] * 65535.f;
|
|
||||||
float L, a, b;
|
|
||||||
Color::XYZ2Lab(XX, YY, ZZ, L, a, b);//only to see Lab values in console
|
|
||||||
printf("N=%i L=%f a=%f b=%f\n", i, L / 327.68f, a / 327.68f, b / 327.68f);
|
|
||||||
aa += (a / 327.68f);
|
|
||||||
bb += (b / 327.68f);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
aa /= N_c;
|
|
||||||
bb /= N_c;
|
|
||||||
printf("aa=%f bb=%f\n", aa, bb);
|
|
||||||
*/
|
|
||||||
// }
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
double m11, m22, x_DD, y_DD, interm2;
|
double m11, m22, x_DD, y_DD, interm2;
|
||||||
|
|
||||||
@ -3689,97 +3619,21 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa
|
|||||||
interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD);
|
interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD);
|
||||||
m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2;
|
m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2;
|
||||||
m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2;
|
m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2;
|
||||||
// float aa = 0.f;
|
|
||||||
// float bb = 0.f;
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, TX[i], TY[i], TZ[i]);
|
spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, TX[i], TY[i], TZ[i]);
|
||||||
|
|
||||||
/* float XX = TX[i] * 65535.f;
|
|
||||||
float YY = TY[i] * 65535.f;
|
|
||||||
float ZZ = TZ[i] * 65535.f;
|
|
||||||
float L, a, b;
|
|
||||||
Color::XYZ2Lab(XX, YY, ZZ, L, a, b);//only to see Lab values in console
|
|
||||||
// printf("N=%i L=%f a=%f b=%f\n", i, L / 327.68f, a / 327.6 8f, b / 327.68f);
|
|
||||||
aa += (a / 327.68f);
|
|
||||||
bb += (b / 327.68f);
|
|
||||||
wbchro[i].chroab = (sqrt(SQR(a) + SQR(b))) / 327.68f;
|
|
||||||
wbchro[i].chroa = a / 327.68f;
|
|
||||||
wbchro[i].chrob = b / 327.68f;
|
|
||||||
wbchro[i].nn = i;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
std::sort(wbchro, wbchro + N_c + 1, wbchro[0]);
|
|
||||||
float ab5 = 0.f;
|
|
||||||
int n5 = 0;
|
|
||||||
float ab15 = 0.f;
|
|
||||||
int n15 = 0;
|
|
||||||
float ab30 = 0.f;
|
|
||||||
int n30 = 0;
|
|
||||||
float ab50 = 0.f;
|
|
||||||
int n50 = 0;
|
|
||||||
float ab70 = 0.f;
|
|
||||||
int n70 = 0;
|
|
||||||
float ab120 = 0.f;
|
|
||||||
int n120 = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
|
||||||
if (wbchro[i].chroab < 5.f) {
|
|
||||||
ab5 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n5++;
|
|
||||||
} else if (wbchro[i].chroab < 15.f) {
|
|
||||||
ab15 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n15++;
|
|
||||||
} else if (wbchro[i].chroab < 30.f) {
|
|
||||||
ab30 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n30++;
|
|
||||||
} else if (wbchro[i].chroab < 50.f) {
|
|
||||||
ab50 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n50++;
|
|
||||||
} else if (wbchro[i].chroab < 70.f) {
|
|
||||||
ab70 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n70++;
|
|
||||||
} else if (wbchro[i].chroab < 120.f) {
|
|
||||||
ab120 += (wbchro[i].chroa + wbchro[i].chrob);
|
|
||||||
n120++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("N=%i nn=%i chr=%f cha=%f chb=%f\n", i, wbchro[i].nn, wbchro[i].chroab, wbchro[i].chroa, wbchro[i].chrob);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("ab5=%f n5=%i\n", ab5 / n5, n5);
|
|
||||||
printf("ab15=%f n15=%i\n", ab15 / n15, n15);
|
|
||||||
printf("ab30=%f n30=%i\n", ab30 / n30, n30);
|
|
||||||
printf("ab50=%f n50=%i\n", ab50 / n50, n50);
|
|
||||||
printf("ab70=%f n70=%i\n", ab70 / n70, n70);
|
|
||||||
printf("ab120=%f n120=%i\n", ab120 / n120, n120);
|
|
||||||
aa /= N_c;
|
|
||||||
bb /= N_c;
|
|
||||||
printf("aa=%f bb=%f\n", aa, bb);
|
|
||||||
//very low 15 --, 16 -+, 17 + -, 18 +-, 20 ++, 22 -+, 73 ++, 98 ++, 99 -+, 101 -+, 129 ++, 130 -+, 131 --,
|
|
||||||
//low 8 +-, 9 --, 10 --, 12 --, 19 -+, 21 -+, 24 -+, 25 ++, 27 ++, 30 ++, 33++, 34 ++, 36 ++, 37++,38 +-,
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (!separated) {
|
|
||||||
// std::string wbcat02Method = wbpar.wbcat02Method;
|
|
||||||
std::string wbcat02Method = "none";
|
|
||||||
|
|
||||||
for (int tt = 0; tt < N_t; tt++) {
|
for (int tt = 0; tt < N_t; tt++) {
|
||||||
tempw = Txyz[tt].Tem;
|
tempw = Txyz[tt].Tem;
|
||||||
|
|
||||||
if (tempw <= INITIALBLACKBODY) {
|
if (tempw <= INITIALBLACKBODY) {
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref);
|
spectrum_to_color_xyz_blackbody(spec_colorforxcyc[i], tempw, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
double m11, m22, x_DD, y_DD, interm2;
|
double x_DD;
|
||||||
|
|
||||||
if (tempw <= 7000) {
|
if (tempw <= 7000) {
|
||||||
x_DD = -4.6070e9 / (tempw * tempw * tempw) + 2.9678e6 / (tempw * tempw) + 0.09911e3 / tempw + 0.244063;
|
x_DD = -4.6070e9 / (tempw * tempw * tempw) + 2.9678e6 / (tempw * tempw) + 0.09911e3 / tempw + 0.244063;
|
||||||
@ -3787,80 +3641,22 @@ void ColorTemp::tempxy(bool separated, int &repref, float **Tx, float **Ty, floa
|
|||||||
x_DD = -2.0064e9 / (tempw * tempw * tempw) + 1.9018e6 / (tempw * tempw) + 0.24748e3 / tempw + 0.237040;
|
x_DD = -2.0064e9 / (tempw * tempw * tempw) + 1.9018e6 / (tempw * tempw) + 0.24748e3 / tempw + 0.237040;
|
||||||
}
|
}
|
||||||
|
|
||||||
y_DD = -3.0 * x_DD * x_DD + 2.87 * x_DD - 0.275;
|
const double y_DD = -3.0 * x_DD * x_DD + 2.87 * x_DD - 0.275;
|
||||||
//calculate D -daylight in function of s0, s1, s2 and temp ==> x_D y_D
|
//calculate D -daylight in function of s0, s1, s2 and temp ==> x_D y_D
|
||||||
//S(lamda)=So(lambda)+m1*s1(lambda)+m2*s2(lambda)
|
//S(lamda)=So(lambda)+m1*s1(lambda)+m2*s2(lambda)
|
||||||
interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD);
|
const double interm2 = (0.0241 + 0.2562 * x_DD - 0.734 * y_DD);
|
||||||
m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2;
|
const double m11 = (-1.3515 - 1.7703 * x_DD + 5.9114 * y_DD) / interm2;
|
||||||
m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2;
|
const double m22 = (0.03 - 31.4424 * x_DD + 30.0717 * y_DD) / interm2;
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref);
|
spectrum_to_color_xyz_daylight(spec_colorforxcyc[i], m11, m22, Refxyz[i].Xref, Refxyz[i].Yref, Refxyz[i].Zref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//CAT02
|
|
||||||
|
|
||||||
float CAM02BB00 = 1.0, CAM02BB01 = 1.0, CAM02BB02 = 1.0, CAM02BB10 = 1.0, CAM02BB11 = 1.0, CAM02BB12 = 1.0, CAM02BB20 = 1.0, CAM02BB21 = 1.0, CAM02BB22 = 1.0; //for CIECAT02
|
|
||||||
float Xwb = Txyz[tt].XX;
|
|
||||||
float Ywb = 1.;
|
|
||||||
float Zwb = Txyz[tt].ZZ;
|
|
||||||
|
|
||||||
if (wbcat02Method == "icam") {//not used
|
|
||||||
icieCAT02float(Xwb, Ywb, Zwb, CAM02BB00, CAM02BB01, CAM02BB02, CAM02BB10, CAM02BB11, CAM02BB12, CAM02BB20, CAM02BB21, CAM02BB22, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wbcat02Method == "cam") {
|
|
||||||
|
|
||||||
cieCAT02float(Xwb, Ywb, Zwb, CAM02BB00, CAM02BB01, CAM02BB02, CAM02BB10, CAM02BB11, CAM02BB12, CAM02BB20, CAM02BB21, CAM02BB22, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wbcat02Method == "none") {
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
|
||||||
Refxyzcat02[i].Xrefcat = CAM02BB00 * Refxyz[i].Xref + CAM02BB01 * Refxyz[i].Yref + CAM02BB02 * Refxyz[i].Zref ;
|
|
||||||
Refxyzcat02[i].Yrefcat = CAM02BB10 * Refxyz[i].Xref + CAM02BB11 * Refxyz[i].Yref + CAM02BB12 * Refxyz[i].Zref ;
|
|
||||||
Refxyzcat02[i].Zrefcat = CAM02BB20 * Refxyz[i].Xref + CAM02BB21 * Refxyz[i].Yref + CAM02BB22 * Refxyz[i].Zref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//end CAT02
|
|
||||||
|
|
||||||
for (int i = 0; i < N_c; i++) {
|
for (int i = 0; i < N_c; i++) {
|
||||||
/* float X = 65535.f * Refxyzcat02[i].Xrefcat;
|
Tx[i][tt] = Refxyz[i].Xref;
|
||||||
float Y = 65535.f * Refxyzcat02[i].Yrefcat;
|
Ty[i][tt] = Refxyz[i].Yref;
|
||||||
float Z = 65535.f * Refxyzcat02[i].Zrefcat;
|
Tz[i][tt] = Refxyz[i].Zref;
|
||||||
float L, a, b;
|
|
||||||
Color::XYZ2Lab(X, Y, Z, L, a, b);
|
|
||||||
|
|
||||||
double som = (Refxyzcat02[i].Xrefcat + Refxyzcat02[i].Yrefcat + Refxyzcat02[i].Zrefcat);
|
|
||||||
L /= 327.68f;
|
|
||||||
a /= 327.68f;
|
|
||||||
b /= 327.68f;
|
|
||||||
Ta[i][tt] = a;
|
|
||||||
Tb[i][tt] = b;
|
|
||||||
TL[i][tt] = L;
|
|
||||||
TX[i][tt] = X;
|
|
||||||
TY[i][tt] = Y;
|
|
||||||
TZ[i][tt] = Z;
|
|
||||||
*/
|
|
||||||
//som = 1.;
|
|
||||||
// Tx[i][tt] = (float) Refxyz[i].Xref;
|
|
||||||
// Ty[i][tt] = (float) Refxyz[i].Yref;
|
|
||||||
// Tz[i][tt] = (float) Refxyz[i].Zref;
|
|
||||||
|
|
||||||
// if (wbpar.wbcat02Method == "none") {
|
|
||||||
if (wbcat02Method == "none") {
|
|
||||||
|
|
||||||
Tx[i][tt] = (float) Refxyz[i].Xref;
|
|
||||||
Ty[i][tt] = (float) Refxyz[i].Yref;
|
|
||||||
Tz[i][tt] = (float) Refxyz[i].Zref;
|
|
||||||
} else {
|
|
||||||
Tx[i][tt] = (float) Refxyzcat02[i].Xrefcat;
|
|
||||||
Ty[i][tt] = (float) Refxyzcat02[i].Yrefcat;
|
|
||||||
Tz[i][tt] = (float) Refxyzcat02[i].Zrefcat;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4292,54 +4292,49 @@ static void histoxyY(int bfhitc, int bfwitc, const array2D<float> & xc, const ar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void static studentXY(const array2D<float> & YYcurr, const array2D<float> & reffYY, int sizcurr, int Nc, int tt, float & student)
|
float static studentXY(const array2D<float> & YYcurr, const array2D<float> & reffYY, int sizcurr, int Nc, int tt)
|
||||||
{
|
{
|
||||||
//calculate Student coeff YY
|
//calculate Student coeff YY
|
||||||
float somcurrY = 0.f;
|
float somcurrY = 0.f;
|
||||||
float somreffY = 0.f;
|
float somreffY = 0.f;
|
||||||
float somcurr2Y = 0.f;
|
float somcurr2Y = 0.f;
|
||||||
float somreff2Y = 0.f;
|
float somreff2Y = 0.f;
|
||||||
float somsqueccurrY = 0.f;
|
|
||||||
float somsquecreffY = 0.f;
|
|
||||||
int sizestucurrY = sizcurr;
|
|
||||||
int sizestureffY = Nc;
|
|
||||||
|
|
||||||
for (int i = 0; i < sizestucurrY; i++) {
|
for (int i = 0; i < sizcurr; i++) {
|
||||||
somcurrY += 100.f * YYcurr[i][tt];
|
somcurrY += YYcurr[i][tt];
|
||||||
//sum observations first group
|
//sum observations first group
|
||||||
}
|
}
|
||||||
|
somcurrY *= 100.f;
|
||||||
|
|
||||||
for (int i = 0; i < sizestureffY; i++) {
|
for (int i = 0; i < Nc; i++) {
|
||||||
somreffY += 100.f * reffYY[i][tt];
|
somreffY += reffYY[i][tt];
|
||||||
//sum observations second group
|
//sum observations second group
|
||||||
|
|
||||||
}
|
}
|
||||||
|
somreffY *= 100.f;
|
||||||
|
|
||||||
|
for (int i = 0; i < sizcurr; i++) {
|
||||||
for (int i = 0; i < sizestucurrY; i++) {
|
somcurr2Y += SQR(YYcurr[i][tt]);
|
||||||
somcurr2Y += SQR(100.f * YYcurr[i][tt]);
|
|
||||||
//sum sqr observations first group
|
//sum sqr observations first group
|
||||||
|
|
||||||
}
|
}
|
||||||
|
somreffY *= SQR(100.f);
|
||||||
|
|
||||||
for (int i = 0; i < sizestureffY; i++) {
|
for (int i = 0; i < Nc; i++) {
|
||||||
somreff2Y += SQR(100.f * reffYY[i][tt]);
|
somreff2Y += SQR(reffYY[i][tt]);
|
||||||
//sum sqr observations second group
|
//sum sqr observations second group
|
||||||
|
|
||||||
}
|
}
|
||||||
|
somreff2Y *= SQR(100.f);
|
||||||
|
|
||||||
somsqueccurrY = somcurr2Y - (SQR(somcurrY)) / sizestucurrY;
|
const float somsqueccurrY = somcurr2Y - (SQR(somcurrY)) / sizcurr;
|
||||||
//sum sqr differences first
|
//sum sqr differences first
|
||||||
somsquecreffY = somreff2Y - (SQR(somreffY)) / sizestureffY;
|
const float somsquecreffY = somreff2Y - (SQR(somreffY)) / Nc;
|
||||||
//sum sqr differences second
|
//sum sqr differences second
|
||||||
|
|
||||||
float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / (float)sizestucurrY + 1.f / (float)sizestureffY)) / (sizestucurrY + sizestureffY - 2));
|
const float diviY = std::sqrt(((somsqueccurrY + somsquecreffY) * (1.f / sizcurr + 1.f / Nc)) / (sizcurr + Nc - 2));
|
||||||
//divisor student
|
//divisor student
|
||||||
float numerY = ((float)somcurrY / (float)sizestucurrY) - ((float)somreffY / (float)sizestureffY);
|
const float numerY = somcurrY / sizcurr - somreffY / Nc;
|
||||||
//numerator student
|
//numerator student
|
||||||
// printf("num=%f divY=%f \n", numerY, diviY);
|
|
||||||
|
|
||||||
student = numerY / diviY ;
|
return numerY / diviY ;
|
||||||
//student coeeficient
|
//student coeeficient
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4404,9 +4399,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color compare to size of histogram real color
|
Itcwb_sizereference : 3 by default, can be set to 5 ==> size of reference color compare to size of histogram real color
|
||||||
itcwb_delta : 1 by default can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good
|
itcwb_delta : 1 by default can be set between 0 to 5 ==> delta temp to build histogram xy - if camera temp is not probably good
|
||||||
*/
|
*/
|
||||||
// BENCHFUN
|
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
|
|
||||||
|
|
||||||
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB");
|
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix("sRGB");
|
||||||
const float wp[3][3] = {
|
const float wp[3][3] = {
|
||||||
@ -4423,49 +4416,19 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
{wiprof[2][0], wiprof[2][1], wiprof[2][2]}
|
{wiprof[2][0], wiprof[2][1], wiprof[2][2]}
|
||||||
};
|
};
|
||||||
|
|
||||||
array2D<float> xc;
|
const int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20
|
||||||
array2D<float> yc;
|
const int bfhitc = bfh / 10 + 1;
|
||||||
array2D<float> Yc;
|
|
||||||
|
|
||||||
array2D<float> histcurr;
|
array2D<float> xc(bfwitc, bfhitc);
|
||||||
array2D<float> histcurrref;
|
array2D<float> yc(bfwitc, bfhitc);
|
||||||
|
array2D<float> Yc(bfwitc, bfhitc);
|
||||||
array2D<float> xxyycurr;
|
|
||||||
array2D<float> xxyycurr_reduc;
|
|
||||||
array2D<float> xx_curref;
|
|
||||||
array2D<float> yy_curref;
|
|
||||||
array2D<float> YY_curref;
|
|
||||||
array2D<float> xx_curref_reduc;
|
|
||||||
array2D<float> yy_curref_reduc;
|
|
||||||
array2D<float> R_curref_reduc;
|
|
||||||
array2D<float> G_curref_reduc;
|
|
||||||
array2D<float> B_curref_reduc;
|
|
||||||
|
|
||||||
array2D<float> reff_spect_xxyy;
|
|
||||||
array2D<float> reff_spect_xxyy_prov;
|
|
||||||
array2D<float> YYcurr;
|
|
||||||
array2D<float> YY_curref_reduc;
|
|
||||||
array2D<float> YYcurr_reduc;
|
|
||||||
// array2D<float> reffYY;
|
|
||||||
// array2D<float> reffYY_prov;
|
|
||||||
|
|
||||||
array2D<float> reff_spect_yy_camera;
|
|
||||||
array2D<float> reff_spect_xx_camera;
|
|
||||||
|
|
||||||
|
|
||||||
int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20
|
|
||||||
int bfhitc = bfh / 10 + 1;
|
|
||||||
|
|
||||||
xc(bfwitc, bfhitc);
|
|
||||||
yc(bfwitc, bfhitc);
|
|
||||||
Yc(bfwitc, bfhitc);
|
|
||||||
|
|
||||||
typedef struct WbGreen {
|
typedef struct WbGreen {
|
||||||
double green;
|
double green;
|
||||||
float snedecor;//1. actually but put in case of confiance interval
|
float snedecor;//1. actually but put in case of confiance interval
|
||||||
} WbGreen;
|
} WbGreen;
|
||||||
|
|
||||||
constexpr WbGreen gree[118] = {//symetric coefficient between 0.717 and 1.40
|
constexpr WbGreen gree[118] = {//symmetric coefficient between 0.717 and 1.40
|
||||||
{0.400, 1.f},
|
{0.400, 1.f},
|
||||||
{0.500, 1.f},
|
{0.500, 1.f},
|
||||||
{0.550, 1.f},
|
{0.550, 1.f},
|
||||||
@ -4585,7 +4548,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
{3.800, 1.f},
|
{3.800, 1.f},
|
||||||
{4.000, 1.f}
|
{4.000, 1.f}
|
||||||
};
|
};
|
||||||
int N_g = sizeof(gree) / sizeof(gree[0]); //number of green
|
const int N_g = sizeof(gree) / sizeof(gree[0]); //number of green
|
||||||
|
|
||||||
typedef struct RangeGreen {
|
typedef struct RangeGreen {
|
||||||
int begin;
|
int begin;
|
||||||
@ -4593,37 +4556,20 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
int ng;
|
int ng;
|
||||||
} RangeGreen;
|
} RangeGreen;
|
||||||
|
|
||||||
RangeGreen Rangestandard;
|
constexpr RangeGreen Rangestandard = {8, 70, 62};
|
||||||
Rangestandard.begin = 8;
|
constexpr RangeGreen Rangeextand = {4, 77, 73};
|
||||||
Rangestandard.end = 70;
|
const RangeGreen Rangemax = {0, N_g, N_g};
|
||||||
Rangestandard.ng = 62;
|
|
||||||
|
|
||||||
RangeGreen Rangeextand;
|
|
||||||
Rangeextand.begin = 4;
|
|
||||||
Rangeextand.end = 77;
|
|
||||||
Rangeextand.ng = 73;
|
|
||||||
|
|
||||||
RangeGreen Rangemax;
|
|
||||||
Rangemax.begin = 0;
|
|
||||||
Rangemax.end = N_g;
|
|
||||||
Rangemax.ng = N_g;
|
|
||||||
|
|
||||||
RangeGreen Rangegreenused;
|
RangeGreen Rangegreenused;
|
||||||
|
|
||||||
if (settings->itcwb_greenrange == 0) {
|
if (settings->itcwb_greenrange == 0) {
|
||||||
Rangegreenused = Rangestandard;
|
Rangegreenused = Rangestandard;
|
||||||
}
|
} else if (settings->itcwb_greenrange == 1) {
|
||||||
|
|
||||||
else if (settings->itcwb_greenrange == 1) {
|
|
||||||
Rangegreenused = Rangeextand;
|
Rangegreenused = Rangeextand;
|
||||||
} else {
|
} else {
|
||||||
Rangegreenused = Rangemax;
|
Rangegreenused = Rangemax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("rangemin=%i rangmax=%i\n", Rangegreenused.begin, Rangegreenused.end);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct WbTxyz {
|
typedef struct WbTxyz {
|
||||||
double Tem;
|
double Tem;
|
||||||
double XX;
|
double XX;
|
||||||
@ -4785,8 +4731,8 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
|
|
||||||
//calculate R G B multiplier in function illuminant and temperature
|
//calculate R G B multiplier in function illuminant and temperature
|
||||||
const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO))
|
const bool isMono = (ri->getSensorType() == ST_FUJI_XTRANS && raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::MONO))
|
||||||
|| (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO));
|
|| (ri->getSensorType() == ST_BAYER && raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::MONO));
|
||||||
for (int tt = 0; tt < N_t; tt++) {
|
for (int tt = 0; tt < N_t; ++tt) {
|
||||||
double r, g, b;
|
double r, g, b;
|
||||||
float rm, gm, bm;
|
float rm, gm, bm;
|
||||||
ColorTemp WBiter = ColorTemp(Txyz[tt].Tem, greenitc, 1.f, "Custom");
|
ColorTemp WBiter = ColorTemp(Txyz[tt].Tem, greenitc, 1.f, "Custom");
|
||||||
@ -4845,11 +4791,11 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
|
|
||||||
bool separated = true;
|
bool separated = true;
|
||||||
int w = -1;
|
int w = -1;
|
||||||
//printf("greenrefraw=%f\n", greenref);
|
|
||||||
reff_spect_xxyy(N_t, 2 * Nc + 2);
|
array2D<float> reff_spect_xxyy(N_t, 2 * Nc + 2);
|
||||||
reff_spect_xxyy_prov(N_t, 2 * Nc + 2);
|
array2D<float> reff_spect_xxyy_prov(N_t, 2 * Nc + 2);
|
||||||
reff_spect_yy_camera(N_t, 2 * Nc + 2);
|
array2D<float> reff_spect_yy_camera(N_t, 2 * Nc + 2);
|
||||||
reff_spect_xx_camera(N_t, 2 * Nc + 2);
|
array2D<float> reff_spect_xx_camera(N_t, 2 * Nc + 2);
|
||||||
|
|
||||||
//here we select the good spectral color inside the 113 values
|
//here we select the good spectral color inside the 113 values
|
||||||
//call tempxy to calculate for 114 color references Temp and XYZ with cat02
|
//call tempxy to calculate for 114 color references Temp and XYZ with cat02
|
||||||
@ -4896,19 +4842,18 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
|
|
||||||
//calculate x y Y
|
//calculate x y Y
|
||||||
const int sizcurrref = siza;//choice of number of correlate colors in image
|
const int sizcurrref = siza;//choice of number of correlate colors in image
|
||||||
histcurrref(N_t, sizcurrref);
|
array2D<float> histcurrref(N_t, sizcurrref);
|
||||||
xx_curref(N_t, sizcurrref);
|
array2D<float> xx_curref(N_t, sizcurrref);
|
||||||
yy_curref(N_t, sizcurrref);
|
array2D<float> yy_curref(N_t, sizcurrref);
|
||||||
YY_curref(N_t, sizcurrref);
|
array2D<float> YY_curref(N_t, sizcurrref);
|
||||||
xx_curref_reduc(N_t, sizcurrref);
|
array2D<float> xx_curref_reduc(N_t, sizcurrref);
|
||||||
yy_curref_reduc(N_t, sizcurrref);
|
array2D<float> yy_curref_reduc(N_t, sizcurrref);
|
||||||
YY_curref_reduc(N_t, sizcurrref);
|
array2D<float> YY_curref_reduc(N_t, sizcurrref);
|
||||||
R_curref_reduc(N_t, sizcurrref);
|
array2D<float> R_curref_reduc(N_t, sizcurrref);
|
||||||
G_curref_reduc(N_t, sizcurrref);
|
array2D<float> G_curref_reduc(N_t, sizcurrref);
|
||||||
B_curref_reduc(N_t, sizcurrref);
|
array2D<float> B_curref_reduc(N_t, sizcurrref);
|
||||||
|
|
||||||
|
hiss Wbhis[siza];
|
||||||
hiss Wbhis [siza];
|
|
||||||
|
|
||||||
for (int nh = 0; nh < siza; nh++) {
|
for (int nh = 0; nh < siza; nh++) {
|
||||||
Wbhis[nh].histnum = histxy[nh];
|
Wbhis[nh].histnum = histxy[nh];
|
||||||
@ -4995,7 +4940,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
|
|
||||||
for (int i = 0; i < sizcurr2ref; ++i) {
|
for (int i = 0; i < sizcurr2ref; ++i) {
|
||||||
//is condition chroxy necessary ?
|
//is condition chroxy necessary ?
|
||||||
if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral
|
if (((wbchro[sizcu4 - (i + 1)].chrox > 0.1f) && (wbchro[sizcu4 - (i + 1)].chroy > 0.1f)) && wbchro[sizcu4 - (i + 1)].chroxy > 0.0f) { //suppress value too far from reference spectral
|
||||||
w++;
|
w++;
|
||||||
xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox;
|
xx_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chrox;
|
||||||
yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy;
|
yy_curref_reduc[w][repref] = wbchro[sizcu4 - (i + 1)].chroy;
|
||||||
@ -5045,21 +4990,20 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
|
|
||||||
//end first part
|
//end first part
|
||||||
|
|
||||||
|
|
||||||
//Now begin real calculations
|
//Now begin real calculations
|
||||||
separated = false;
|
separated = false;
|
||||||
ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants
|
ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 90 illuminants
|
||||||
|
|
||||||
//calculate x y Y
|
//calculate x y Y
|
||||||
int sizcurr = siza;//choice of number of correlate colors in image
|
int sizcurr = siza;//choice of number of correlate colors in image
|
||||||
histcurr(N_t, sizcurr);
|
array2D<float> histcurr(N_t, sizcurr);
|
||||||
xxyycurr(N_t, 2 * sizcurr);
|
array2D<float> xxyycurr(N_t, 2 * sizcurr);
|
||||||
xxyycurr_reduc(N_t, 2 * sizcurr);
|
array2D<float> xxyycurr_reduc(N_t, 2 * sizcurr);
|
||||||
float minstud = 100000.f;
|
float minstud = 100000.f;
|
||||||
int goodref = 1;
|
int goodref = 1;
|
||||||
|
|
||||||
YYcurr(N_t, sizcurr);
|
array2D<float> YYcurr(N_t, sizcurr);
|
||||||
YYcurr_reduc(N_t, sizcurr);
|
array2D<float> YYcurr_reduc(N_t, sizcurr);
|
||||||
|
|
||||||
//calculate x y z for each pixel with multiplier rmm gmm bmm
|
//calculate x y z for each pixel with multiplier rmm gmm bmm
|
||||||
|
|
||||||
@ -5089,17 +5033,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float student = 0.f;
|
const float abstud = std::fabs(studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kk, tt));
|
||||||
|
|
||||||
studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kk, tt, student); //for xy
|
|
||||||
|
|
||||||
const float abstud = std::fabs(student);
|
|
||||||
|
|
||||||
if (abstud < minstud) { // find the minimum Student
|
if (abstud < minstud) { // find the minimum Student
|
||||||
minstud = abstud;
|
minstud = abstud;
|
||||||
goodref = tt;
|
goodref = tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra) {
|
if (extra) {
|
||||||
@ -5184,10 +5123,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float studentgr = 0.f;
|
const float abstudgr = std::fabs(studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kkg, tt));
|
||||||
|
|
||||||
studentXY(xxyycurr_reduc, reff_spect_xxyy, 2 * w, 2 * kkg, tt, studentgr); //for xy
|
|
||||||
const float abstudgr = std::fabs(studentgr);
|
|
||||||
|
|
||||||
if (abstudgr < minstudgr) { // find the minimum Student
|
if (abstudgr < minstudgr) { // find the minimum Student
|
||||||
minstudgr = abstudgr;
|
minstudgr = abstudgr;
|
||||||
|
@ -823,7 +823,6 @@ void ColorAppearance::read (const ProcParams* pp, const ParamsEdited* pedited)
|
|||||||
nexttemp = pp->wb.temperature;
|
nexttemp = pp->wb.temperature;
|
||||||
nextgreen = pp->wb.green;
|
nextgreen = pp->wb.green;
|
||||||
|
|
||||||
printf("temp=%f green=%f\n", nexttemp, nextgreen);
|
|
||||||
if (pedited) {
|
if (pedited) {
|
||||||
degree->setEditedState (pedited->colorappearance.degree ? Edited : UnEdited);
|
degree->setEditedState (pedited->colorappearance.degree ? Edited : UnEdited);
|
||||||
degreeout->setEditedState (pedited->colorappearance.degreeout ? Edited : UnEdited);
|
degreeout->setEditedState (pedited->colorappearance.degreeout ? Edited : UnEdited);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user