From 36cf9ece44c96557a2fe63a19934ce660795160b Mon Sep 17 00:00:00 2001 From: Desmis Date: Wed, 30 Jan 2019 14:24:03 +0100 Subject: [PATCH] Add forgotten invershap with deltaE --- rtengine/improcfun.h | 2 +- rtengine/iplocallab.cc | 149 +++++++++-------------------------------- rtgui/locallab.cc | 4 +- 3 files changed, 35 insertions(+), 120 deletions(-) diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 74b8bb584..ed8b6e4fa 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -313,7 +313,7 @@ public: void Sharp_Local(int call, float **loctemp, int senstype, const float hueref, const float chromaref, const float lumaref, const local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk); // void Sharp_Local(int call, float **loctemp, int senstype, const float hueplus, const float huemoins, const float hueref, const float dhue, const float chromaref, const local_params& lp, LabImage* original, LabImage* transformed, int cx, int cy, int sk); - void InverseSharp_Local(float **loctemp, const float hueplus, const float huemoins, const float hueref, const float dhue, const float chromaref, const local_params& lp, LabImage* original, LabImage* transformed, int cx, int cy, int sk); + void InverseSharp_Local(float **loctemp, const float hueref, const float lumaref, const float chromaref, const local_params& lp, LabImage* original, LabImage* transformed, int cx, int cy, int sk); void Tile_calc(int tilesize, int overlap, int kall, int imwidth, int imheight, int &numtiles_W, int &numtiles_H, int &tilewidth, int &tileheight, int &tileWskip, int &tileHskip); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 139b40468..71a4dd22c 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -2947,26 +2947,15 @@ static void calclight(float lum, float koef, float & lumnew, LUTf & lightCurvel } -void ImProcFunctions::InverseSharp_Local(float **loctemp, const float hueplus, const float huemoins, const float hueref, const float dhue, const float chromaref, const local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk) +void ImProcFunctions::InverseSharp_Local(float **loctemp, const float hueref, const float lumaref, const float chromaref, const local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk) { //local sharp // BENCHFUN const float ach = (float)lp.trans / 100.f; - constexpr float delhu = 0.1f; //between 0.05 and 0.2 - - const float apl = (-1.f) / delhu; - const float bpl = - apl * hueplus; - const float amo = 1.f / delhu; - const float bmo = - amo * huemoins; - - - const float pb = 4.f; - const float pa = (1.f - pb) / 40.f; - - const float ahu = 1.f / (2.8f * lp.senssha - 280.f); - const float bhu = 1.f - ahu * 2.8f * lp.senssha; int GW = transformed->W; int GH = transformed->H; + float refa = chromaref * cos(hueref); + float refb = chromaref * sin(hueref); LabImage *origblur = nullptr; @@ -3020,11 +3009,11 @@ void ImProcFunctions::InverseSharp_Local(float **loctemp, const float hueplus, c for (int x = 0; x < transformed->W; x++) { int lox = cx + x; #ifdef __SSE2__ - float rhue = atan2Buffer[x]; - float rchro = sqrtBuffer[x]; +// float rhue = atan2Buffer[x]; +// float rchro = sqrtBuffer[x]; #else - float rhue = xatan2f(origblur->b[y][x], origblur->a[y][x]); - float rchro = sqrt(SQR(origblur->b[y][x]) + SQR(origblur->a[y][x])) / 327.68f; +// float rhue = xatan2f(origblur->b[y][x], origblur->a[y][x]); +// float rchro = sqrt(SQR(origblur->b[y][x]) + SQR(origblur->a[y][x])) / 327.68f; #endif int zone; float localFactor = 1.f; @@ -3035,115 +3024,37 @@ void ImProcFunctions::InverseSharp_Local(float **loctemp, const float hueplus, c calcTransitionrect(lox, loy, ach, lp, zone, localFactor); } - //prepare shape detection - float khu = 0.f; - float kch = 1.f; - float fach = 1.f; - float deltachro = fabs(rchro - chromaref); - float deltahue = fabs(rhue - hueref); + float rL = origblur->L[y][x] / 327.68f; + float reducdE = 0.f; + float dE = 0.f; + dE = sqrt(SQR(refa - origblur->a[y][x] / 327.68f) + SQR(refb - origblur->b[y][x] / 327.68f) + SQR(lumaref - rL)); + float mindE = 2.f + 0.05f * lp.senssha;//between 2 and 7 + float maxdE = 5.f + 1.5f * lp.senssha; // between 5 and 150, we can chnage this values - if (deltahue > rtengine::RT_PI) { - deltahue = - (deltahue - 2.f * rtengine::RT_PI); + float ar = 1.f / (mindE - maxdE); + + float br = - ar * maxdE; + + if (dE > maxdE) { + reducdE = 0.f; } - float deltaE = 20.f * deltahue + deltachro; //pseudo deltaE between 0 and 280 - - //kch to modulate action with chroma - if (deltachro < 160.f * SQR(lp.senssha / 100.f)) { - kch = 1.f; - } else { - float ck = 160.f * SQR(lp.senssha / 100.f); - float ak = 1.f / (ck - 160.f); - float bk = -160.f * ak; - kch = ak * deltachro + bk; + if (dE > mindE && dE <= maxdE) { + reducdE = ar * dE + br; } - if (lp.senssha < 40.f) { - kch = pow(kch, pa * lp.senssha + pb); //increase under 40 + if (dE <= mindE) { + reducdE = 1.f; } - - // algo with detection of hue ==> artifacts for noisy images ==> denoise before - if (lp.senssha < 20.f) { //to try... - //hue detection - if ((hueref + dhue) < rtengine::RT_PI && rhue < hueplus && rhue > huemoins) { //transition are good - if (rhue >= hueplus - delhu) { - khu = apl * rhue + bpl; - } else if (rhue < huemoins + delhu) { - khu = amo * rhue + bmo; - } else { - khu = 1.f; - } - - } else if ((hueref + dhue) >= rtengine::RT_PI && (rhue > huemoins || rhue < hueplus)) { - if (rhue >= hueplus - delhu && rhue < hueplus) { - khu = apl * rhue + bpl; - } else if (rhue >= huemoins && rhue < huemoins + delhu) { - khu = amo * rhue + bmo; - } else { - khu = 1.f; - } - - } - - if ((hueref - dhue) > -rtengine::RT_PI && rhue < hueplus && rhue > huemoins) { - if (rhue >= hueplus - delhu && rhue < hueplus) { - khu = apl * rhue + bpl; - } else if (rhue >= huemoins && rhue < huemoins + delhu) { - khu = amo * rhue + bmo; - } else { - khu = 1.f; - } - - } else if ((hueref - dhue) <= -rtengine::RT_PI && (rhue > huemoins || rhue < hueplus)) { - if (rhue >= hueplus - delhu && rhue < hueplus) { - khu = apl * rhue + bpl; - } else if (rhue >= huemoins && rhue < huemoins + delhu) { - khu = amo * rhue + bmo; - } else { - khu = 1.f; - } - - } - - if (deltaE < 2.8f * lp.senssha) { - fach = khu; - } else { - fach = khu * (ahu * deltaE + bhu); - } - - - float kcr = 10.f; - - if (rchro < kcr) { - fach *= (1.f / (kcr * kcr)) * rchro * rchro; - } - - if (lp.qualmet >= 1) { - } else { - fach = 1.f; - } - - //fach = khu ; - - } else { - /* - float kcr = 8.f; - if(lp.senssha > 30.f){ - if (rchro < kcr) { - fach *= (1.f / (kcr)) * rchro; - - } - } - */ + if (lp.senssha > 99) { + reducdE = 1.f; } - - switch (zone) { case 0: { // outside selection and outside transition zone => full effect, no transition float difL = loctemp[y][x] - original->L[y][x]; - transformed->L[y][x] = CLIP(original->L[y][x] + difL * kch * fach); + transformed->L[y][x] = CLIP(original->L[y][x] + difL * reducdE); break; } @@ -3154,7 +3065,7 @@ void ImProcFunctions::InverseSharp_Local(float **loctemp, const float hueplus, c float factorx = 1.f - localFactor; difL *= factorx; - transformed->L[y][x] = CLIP(original->L[y][x] + difL * kch * fach); + transformed->L[y][x] = CLIP(original->L[y][x] + difL * reducdE); break; } @@ -4189,6 +4100,10 @@ void ImProcFunctions::InverseColorLight_Local(const struct local_params & lp, LU reducdE = 1.f; } + if (lp.sens > 99) { + reducdE = 1.f; + } + float th_r = 0.01f; if (rL > th_r) { //to avoid crash with very low gamut in rare cases ex : L=0.01 a=0.5 b=-0.9 @@ -7080,7 +6995,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o huemoins = hueref - dhuesha + 2.f * rtengine::RT_PI; } - InverseSharp_Local(loctemp, hueplus, huemoins, hueref, dhuesha, chromaref, lp, original, transformed, cx, cy, sk); + InverseSharp_Local(loctemp, hueref, lumaref, chromaref, lp, original, transformed, cx, cy, sk); } // } diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index 0a34d8df4..8ee5916ba 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -2410,7 +2410,7 @@ void Locallab::inversshaChanged() if (multiImage && inverssha->get_inconsistent()) { sensisha->show(); } else if (inverssha->get_active()) { - sensisha->hide(); + sensisha->show(); } else { sensisha->show(); } @@ -4058,7 +4058,7 @@ void Locallab::updateSpecificGUIState() if (multiImage && inverssha->get_inconsistent()) { sensisha->show(); } else if (inverssha->get_active()) { - sensisha->hide(); + sensisha->show(); } else { sensisha->show(); }