From 9773f1bd98930e43930c19625b491eb156208bbb Mon Sep 17 00:00:00 2001 From: Desmis Date: Fri, 6 Mar 2020 10:41:58 +0100 Subject: [PATCH] Improve results when chroma is very low --- rtengine/colortemp.cc | 27 ++++++++++++++++++++++++++- rtengine/colortemp.h | 3 +++ rtengine/rawimagesource.cc | 30 ++++++++++++++++++------------ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/rtengine/colortemp.cc b/rtengine/colortemp.cc index 0b49658cd..4d5cb42f2 100644 --- a/rtengine/colortemp.cc +++ b/rtengine/colortemp.cc @@ -2444,7 +2444,30 @@ const double ColorTemp::JDC468_greyf26_156_spect[97] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; */ +//A1 0.0912 0.1228 0.1712 0.2978 0.3713 0.4241 0.4861 0.5255 0.5355 0.5363 0.5237 0.5251 +// 0.5722 0.6554 0.6936 0.6675 0.6203 0.5651 0.5116 0.4825 0.4714 0.4866 0.5320 0.5729 +// 0.5968 0.6069 0.6131 0.6198 0.6285 0.6325 0.6316 0.6282 0.6227 0.6196 0.6215 0.6337 +const double ColorTemp::Colorlab_n80_5_9_5_9spect[97] = { + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0912, 0.1, 0.1228, 0.15, 0.1712, 0.2, 0.2978, 0.32, 0.3713, 0.41, 0.4241, 0.44, 0.4861, 0.51, 0.5255, 0.53, 0.5355, 0.534, 0.5363, 0.53, 0.5237, 0.524, 0.5251, 0.56, + 0.5722, 0.6, 0.6554, 0.67, 0.6936, 0.67, 0.6675, 0.65, 0.6203, 0.6, 0.5651, 0.54, 0.5116, 0.5, 0.4825, 0.48, 0.4714, 0.48, 0.4866, 0.5, 0.5320, 0.55, 0.5729, 0.58, + 0.5968, 0.6, 0.6069, 0.61, 0.6131, 0.615, 0.6198, 0.62, 0.6285, 0.63, 0.6325, 0.632, 0.6316, 0.63, 0.6282, 0.625, 0.6227, 0.62, 0.6196, 0.62, 0.6215, 0.63, 0.6337, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 +}; +/* +//A2 0.0385 0.0514 0.0711 0.1229 0.1528 0.1744 0.1999 0.2163 0.2209 0.2216 0.2167 0.2185 +//0.2414 0.2813 0.3012 0.2922 0.2734 0.2511 0.2292 0.2173 0.2127 0.2183 0.2354 0.2508 +//0.2599 0.2637 0.2662 0.2689 0.2725 0.2742 0.2738 0.2724 0.2701 0.2689 0.2697 0.2747 + +const double ColorTemp::Colorlab_n57_5_6_9spect[97] = { + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0385, 0.04, 0.0514, 0.06, 0.0711, 0.1, 0.1229, 0.14, 0.1528, 0.16, 0.1744, 0.18, 0.1999, 0.2, 0.2163, 0.22, 0.2209, 0.221, 0.2216, 0.22, 0.2167, 0.216, 0.2185, 0.23, + 0.2414, 0.26, 0.2813, 0.3, 0.3012, 0.3, 0.2922, 0.28, 0.2734, 0.26, 0.2511, 0.24, 0.2292, 0.22, 0.2173, 0.215, 0.2127, 0.215, 0.2183, 0.22, 0.2354, 0.24, 0.2508, 0.255, + 0.2599, 0.26, 0.2637, 0.263, 0.2662, 0.267, 0.2689, 0.27, 0.2725, 0.273, 0.2742, 0.274, 0.2738, 0.273, 0.2724, 0.271, 0.2701, 0.27, 0.2689, 0.269, 0.2697, 0.27, 0.2747, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 +}; +*/ /* * Name: XYZtoCorColorTemp.c * @@ -3485,7 +3508,9 @@ void ColorTemp::tempxy(bool separated, int repref, float **Tx, float **Ty, float J570_NeuQ1_spect, J570_NeuS7_spect, J570_NeuV10_spect, J570_NeuW18_spect, J570_NeuZ14_spect, //189 J570_NeuC18_spect, J570_NeuD17_spect, J570_NeuJ11_spect, J570_NeuL4_spect, Colorlab_n72_n2_spect, - Colorlab_10_n70_spect, Colorlab_n33_n70_spect, Colorlab_n8_n74_spect, Colorlab_19_n69_spect, Colorlab_n80_10_spect, Colorlab_n80_26_spect + Colorlab_10_n70_spect, Colorlab_n33_n70_spect, Colorlab_n8_n74_spect, Colorlab_19_n69_spect, Colorlab_n80_10_spect, Colorlab_n80_26_spect, + Colorlab_n80_5_9_5_9spect //, Colorlab_n57_5_6_9spect + /*JDC468_greyc14_66_spect, JDC468_greym13_325_spect, JDC468_greyf26_156_spect*/ }; diff --git a/rtengine/colortemp.h b/rtengine/colortemp.h index e3c899f82..89c324490 100644 --- a/rtengine/colortemp.h +++ b/rtengine/colortemp.h @@ -367,6 +367,9 @@ public: static const double Colorlab_19_n69_spect[97]; static const double Colorlab_n80_10_spect[97]; static const double Colorlab_n80_26_spect[97]; + static const double Colorlab_n80_5_9_5_9spect[97]; +// static const double Colorlab_n57_5_6_9spect[97]; + /* static const double JDC468_greyc14_66_spect[97]; static const double JDC468_greym13_325_spect[97]; diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index c4226585a..0326609cd 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -4412,19 +4412,19 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double Copyright (c) Jacques Desmis 6 - 2018 jdesmis@gmail.com Copyright (c) Ingo Weyrich 3 - 2020 (heckflosse67@gmx.de) - This algorithm try to find temperature correlation between 20 to 203 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. + This algorithm try to find temperature correlation between 20 to 201 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. I have test many many algorithms to find the first one that work :) Probably (sure) there are improvement to do... I have create a table temperature with temp and white point with 100 values between 2000K and 12000K we can obviously change these values, more...with different steps - I have create or recuparate and transformed 203 spectral colors from Colorchecker24, others color and my 468 colors target, or from web flowers, etc. with a step of 5nm, I think it is large enough. - I think this value of 203 is now complete: I tested correlation with 60, 90, 100, 120, 155...better student increase with number of color, but now it seems stabilized + I have create or recuparate and transformed 201 spectral colors from Colorchecker24, others color and my 468 colors target, or from web flowers, etc. with a step of 5nm, I think it is large enough. + I think this value of 201 is now complete: I tested correlation with 60, 90, 100, 120, 155...better student increase with number of color, but now it seems stabilized Of course we can increase this number :) 1) for the current raw file we create a table for each temp of RGB multipliers 2) then, I choose the "camera temp" to initialize calculation (why not) - 3) for this temp, I calculated XYZ values for the 203 spectral datas + 3) for this temp, I calculated XYZ values for the 201 spectral datas 4) then I create for the image an "histogram", but for xyY (Cie 1931 color space) 5) for each pixel (in fact to accelerate only 1/10 for and 1/10 for y), I determine for each couple xy, the number of occurences 6) I sort this result in ascending order @@ -4764,7 +4764,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double {12001., 0.960440, 1.601019} }; const int N_t = sizeof(Txyz) / sizeof(Txyz[0]); //number of temperature White point - constexpr int Nc = 200 + 1;//200 number of reference spectral colors, I think it is enough to retrieve good values + constexpr int Nc = 201 + 1;//200 number of reference spectral colors, I think it is enough to retrieve good values array2D Tx(N_t, Nc); array2D Ty(N_t, Nc); array2D Tz(N_t, Nc); @@ -4863,7 +4863,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double array2D reff_spect_xx_camera(N_t, 2 * Nc + 2); //here we select the good spectral color inside the 113 values - //call tempxy to calculate for 203 color references Temp and XYZ with cat02 + //call tempxy to calculate for 201 color references Temp and XYZ with cat02 ColorTemp::tempxy(separated, repref, Tx, Ty, Tz, Ta, Tb, TL, TX, TY, TZ, wbpar); //calculate chroma xy (xyY) for Z known colors on under 200 illuminants @@ -4998,7 +4998,9 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } estimchrom /= sizcu4; - + if (settings->verbose) { + printf("estimchrom=%f\n", estimchrom); + } if (settings->itcwb_sort) { //sort in ascending with chroma values std::sort(wbchro, wbchro + sizcu4, wbchro[0]); } @@ -5021,7 +5023,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double int maxnb = rtengine::LIM(settings->itcwb_sizereference, 1, 5); if (settings->itcwb_thres > 39) { - maxnb = 203 / settings->itcwb_thres; + maxnb = 201 / settings->itcwb_thres; } for (int nb = 1; nb <= maxnb; ++nb) { //max 5 iterations for Itcwb_thres=33, after trial 3 is good in most cases but in some cases 5 @@ -5178,13 +5180,14 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double } //degrade correllation with color high chroma, but not too much...seems not good, but keep in case of?? - if (estimchrom < 0.025f) {//very smal value of chroma for image - + //I suppress this old behavior replace by tint += 0.02 + /* if (estimchrom < 0.025f) {//very smal value of chroma for image + //enable strong values good_spectral[0] = true;//blue good_spectral[11] = true;//green good_spectral[62] = true;//red } - +*/ int kkg = -1; for (int i = 0; i < Nc ; ++i) { if (good_spectral[i]) { @@ -5253,7 +5256,10 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double tempitc = Txyz[goodref].Tem; greenitc = gree[greengood].green; - + if (estimchrom < 0.025f) { + float ac = -2.40f * estimchrom + 0.06f;//small empirical correction, maximum 0.06 if chroma=0 for all image, currently for very low chroma +0.02 + greenitc += ac; + } } avg_rm = 10000.f * rmm[goodref];