From c9c02c137bc6d542882ae4dd895b4dd29f6d864b Mon Sep 17 00:00:00 2001 From: Desmis Date: Wed, 13 Sep 2017 08:49:56 +0200 Subject: [PATCH] change calculation in curve brightness CIECAM --- rtengine/improcfun.cc | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 6d6fccc88..c8faa4ce0 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -1681,10 +1681,11 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } } - if (alg >= 2 && la < 200.f) { - la = 200.f; - } - + /* + if (alg >= 2 && la < 200.f) { + la = 200.f; + } + */ const float la2 = float (params->colorappearance.adaplum); // level of adaptation @@ -1775,6 +1776,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } float sum = 0.f; + float sumQ = 0.f; #ifdef _OPENMP const int numThreads = min (max (width * height / 65536, 1), omp_get_max_threads()); @@ -1794,7 +1796,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int hist16Qthr.clear(); } - #pragma omp for reduction(+:sum) + #pragma omp for reduction(+:sum,sumQ) for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) { //rough correspondence between L and J @@ -1839,11 +1841,26 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int hist16Jthr[ (int) ((koef * lab->L[i][j]))]++; //evaluate histogram luminance L # J } + //estimation of wh only with La + float whestim = 500.f; + + if (la < 200.f) { + whestim = 200.f; + } else if (la < 2500.f) { + whestim = 350.f; + } else { + whestim = 500.f; + } + if (needQ) { - hist16Qthr[ (int) (sqrtf ((koef * (lab->L[i][j])) * 32768.f))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L + hist16Qthr[CLIP ((int) (32768.f * sqrt ((koef * (lab->L[i][j])) / 32768.f)))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L + //perhaps needs to introduce whestim ?? + // hist16Qthr[ (int) (sqrtf ((koef * (lab->L[i][j])) * 32768.f))]++; //for brightness Q : approximation for Q=wh*sqrt(J/100) J not equal L } sum += koef * lab->L[i][j]; //evaluate mean J to calculate Yb + sumQ += whestim * sqrt ((koef * (lab->L[i][j])) / 32768.f); + //can be used in case of... } #pragma omp critical @@ -1857,14 +1874,16 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int } } + float meanQ; if (std::isnan (mean)) { mean = (sum / ((height) * width)) / 327.68f; //for Yb for all image...if one day "pipette" we can adapt Yb for each zone + meanQ = (sumQ / ((height) * width));//in case of + } } - //evaluate lightness, contrast } @@ -1937,6 +1956,8 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int float cz, wh, pfl; Ciecam02::initcam1float (gamu, yb, pilot, f, la, xw, yw, zw, n, d, nbb, ncb, cz, aw, wh, pfl, fl, c); + //printf ("wh=%f \n", wh); + const float pow1 = pow_F ( 1.64f - pow_F ( 0.29f, n ), 0.73f ); float nj, nbbj, ncbj, czj, awj, flj; Ciecam02::initcam2float (gamu, yb2, pilotout, f2, la2, xw2, yw2, zw2, nj, dj, nbbj, ncbj, czj, awj, flj); @@ -1954,7 +1975,7 @@ void ImProcFunctions::ciecam_02float (CieImage* ncie, float adap, int begh, int const bool LabPassOne = ! ((params->colorappearance.tonecie && (epdEnabled)) || (params->sharpening.enabled && settings->autocielab && execsharp) || (params->dirpyrequalizer.enabled && settings->autocielab) || (params->defringe.enabled && settings->autocielab) || (params->sharpenMicro.enabled && settings->autocielab) || (params->impulseDenoise.enabled && settings->autocielab) || (params->colorappearance.badpixsl > 0 && settings->autocielab)); - + //printf("coQ=%f\n", coefQ); if (needJ) { if (!CAMBrightCurveJ) {