From 3ca1fa8719e6db204fc4fb0df22468697b0f9cea Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 26 May 2019 14:00:00 +0200 Subject: [PATCH] Various improvment to Retinex (label, double, maxchro...) --- rtdata/languages/default | 2 +- rtengine/iplocallab.cc | 37 ++++++++++++++++++++++++++----------- rtengine/ipretinex.cc | 2 +- rtengine/procparams.cc | 6 +++--- rtengine/procparams.h | 6 +++--- rtgui/locallab.cc | 18 +++++++++--------- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index fc3e7468e..c6e71a092 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -2097,7 +2097,7 @@ TP_LOCALLAB_STRGRID;Strength TP_LOCALLAB_TM;Tone Mapping TP_LOCALLAB_STR;Strength TP_LOCALLAB_NEIGH;Radius -TP_LOCALLAB_VART;Contrast +TP_LOCALLAB_VART;Contrast (variance) TP_LOCALLAB_SENSI;Scope TP_LOCALLAB_SENSI_TOOLTIP;Adjust scope of action:\nSmall values limit action to colors very similar to those under the center spot.\nHigh values let the tool act upon a wider range of colors.\nValues smaller than 20 lead to a better algorithm. TP_LOCALLAB_SENSIH;Scope diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 67a07c2fd..27e65ff51 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -2400,20 +2400,21 @@ void ImProcFunctions::transit_shapedetect_retinex(int senstype, LabImage * bufex float reducdE; calcreducdE(dE, maxdE, mindE, maxdElim, mindElim, lp.iterat, limscope, varsens , reducdE); - const float realstrdE = reducdE * cli; + // const float realstrdE = reducdE * cli; reducdE /= 100.f; cli *= reducdE; clc *= reducdE; cli *= (1.f + strcli); + // clc *= (1.f + strcli); if (rL > 0.1f) { //to avoid crash with very low gamut in rare cases ex : L=0.01 a=0.5 b=-0.9 if (senstype == 4) {//all except color and light (TODO) and exposure float lightc = bufexporig->L[loy - begy][lox - begx]; float fli = 1.f + cli; float diflc = lightc * fli - original->L[y][x]; - float diflc2 = 328.f * realstrdE; + // float diflc2 = 328.f * realstrdE; diflc *= localFactor; - diflc2 *= localFactor; + // diflc2 *= localFactor; if(!showmas) transformed->L[y][x] = CLIP(original->L[y][x] + diflc); else transformed->L[y][x] = bufmask->L[loy - begy][lox - begx]; ; //bufexporig->L[loy - begy][lox - begx]; @@ -6005,18 +6006,32 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o orig1[ir][jr] = sqrt(SQR(transformed->a[ir][jr]) + SQR(transformed->b[ir][jr])); } } + float maxChro = orig1[0][0]; +#ifdef _OPENMP + #pragma omp parallel for reduction(max:maxChro) schedule(dynamic,16) +#endif + + for (int ir = 0; ir < Hd; ir++) { + for (int jr = 0; jr < Wd; jr++) { + maxChro = rtengine::max(maxChro, orig1[ir][jr]); + } + } + float divchro = maxChro; //first step change saturation whithout Retinex ==> gain of time and memory float satreal = lp.str * params->locallab.spots.at(sp).chrrt / 100.f; + if(params->locallab.spots.at(sp).chrrt <= 0.2f) { + satreal /= 10.f; + } DiagonalCurve reti_satur({ DCT_NURBS, 0, 0, - 0.1, 0.1 + satreal / 150.0, - 0.7, min(1.0, 0.7 + satreal / 300.0), + 0.2, 0.2 + satreal / 250.0, + 0.6, min(1.0, 0.6 + satreal / 250.0), 1, 1 }); - - if(params->locallab.spots.at(sp).chrrt > 30.f){ //second step active Retinex Chroma + + if(params->locallab.spots.at(sp).chrrt > 40.f){ //second step active Retinex Chroma ImProcFunctions::MSRLocal(sp, 0, bufreti, bufmask, buforig, buforigmas, orig, tmpl->L, orig1, Wd, Hd, params->locallab, sk, locRETgainCcurve, 1, 4, 0.8f, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax, locccmasretiCurve, lcmasretiutili, locllmasretiCurve, llmasretiutili, lochhmasretiCurve, lhmasretiutili, llretiMask, transformed, lp.enaretiMasktmap, lp.enaretiMask); } @@ -6032,10 +6047,10 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o float2 sincosval; sincosval.y = Chprov == 0.0f ? 1.f : bufreti->a[ir][jr] / Chprov; sincosval.x = Chprov == 0.0f ? 0.f : bufreti->b[ir][jr] / Chprov; - if(params->locallab.spots.at(sp).chrrt <= 30.f) {//first step - float buf = LIM01(orig[ir][jr] / 40000.f); + if(params->locallab.spots.at(sp).chrrt <= 40.f) {//first step + float buf = LIM01(orig[ir][jr] / divchro); buf = reti_satur.getVal(buf); - buf *= 40000.f; + buf *= divchro; orig[ir][jr] = buf; } tmpl->a[ir][jr] = orig[ir][jr] * sincosval.y; @@ -6083,7 +6098,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o if (!lp.invret) { - transit_shapedetect_retinex(5, tmpl, bufmask, buforigmas, buflight, bufchro, hueref, chromaref, lumaref, lp, original, transformed, cx, cy, sk); + transit_shapedetect_retinex(5, tmpl, bufmask, buforigmas, buflight, bufchro, hueref, chromaref, lumaref, lp, original, transformed, cx, cy, sk); } else { InverseReti_Local(lp, hueref, chromaref, lumaref, original, transformed, tmpl, cx, cy, 1, sk); } diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index 57dbafdf3..7b1ddcf64 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -1385,7 +1385,7 @@ void ImProcFunctions::MSRLocal(int sp, int lum, LabImage * bufreti, LabImage * b delete [] buffer; delete [] outBuffer; outBuffer = nullptr; - float str = strength * (chrome == 0 ? 1.f : 0.8f * chrT); + float str = strength * (chrome == 0 ? 1.f : 0.8f * (chrT - 0.4f)); const float maxclip = (chrome == 0 ? 32768.f : 50000.f); if (scal != 1) { diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index dd95eff82..fd0757848 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -2470,9 +2470,9 @@ LocallabParams::LocallabSpot::LocallabSpot() : expreti(false), retinexMethod("high"), str(0.0), - chrrt(0), - neigh(150), - vart(70), + chrrt(0.0), + neigh(150.), + vart(70.), dehaz(0), sensih(30), localTgaincurve{(double)FCT_MinMaxCPoints, 0.0, 0.12, 0.35, 0.35, 0.70, 0.50, 0.35, 0.35, 1.00, 0.12, 0.35, 0.35}, diff --git a/rtengine/procparams.h b/rtengine/procparams.h index 7405b536b..8a95bb593 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -1071,9 +1071,9 @@ struct LocallabParams { bool expreti; Glib::ustring retinexMethod; double str; - int chrrt; - int neigh; - int vart; + double chrrt; + double neigh; + double vart; int dehaz; int sensih; std::vector localTgaincurve; diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index a20df8edb..62750a4db 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -150,9 +150,9 @@ Locallab::Locallab(): satur(Gtk::manage(new Adjuster(M("TP_LOCALLAB_SATUR"), -100., 100., 0.1, 0.))),//by default satur = 0 ==> use Mantiuk value // Retinex str(Gtk::manage(new Adjuster(M("TP_LOCALLAB_STR"), 0., 100., 0.1, 0.0))), - chrrt(Gtk::manage(new Adjuster(M("TP_LOCALLAB_CHRRT"), 0, 100, 1, 0))), - neigh(Gtk::manage(new Adjuster(M("TP_LOCALLAB_NEIGH"), 4, 500, 1, 150))), - vart(Gtk::manage(new Adjuster(M("TP_LOCALLAB_VART"), 10, 500, 1, 70))), + chrrt(Gtk::manage(new Adjuster(M("TP_LOCALLAB_CHRRT"), 0.0, 100.0, 0.1, 0.0))), + neigh(Gtk::manage(new Adjuster(M("TP_LOCALLAB_NEIGH"), 4., 500., 0.5, 150.))), + vart(Gtk::manage(new Adjuster(M("TP_LOCALLAB_VART"), 10.0, 500., 0.1, 70.))), dehaz(Gtk::manage(new Adjuster(M("TP_LOCALLAB_DEHAZ"), 0, 100, 1, 0))), sensih(Gtk::manage(new Adjuster(M("TP_LOCALLAB_SENSIH"), 0, 100, 1, 30))), softradiusret(Gtk::manage(new Adjuster(M("TP_LOCALLAB_GUIDFILTER"), 0.0, 100.0, 0.1, 0.))), @@ -2131,9 +2131,9 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited) } pp->locallab.spots.at(pp->locallab.selspot).str = str->getValue(); - pp->locallab.spots.at(pp->locallab.selspot).chrrt = chrrt->getIntValue(); - pp->locallab.spots.at(pp->locallab.selspot).neigh = neigh->getIntValue(); - pp->locallab.spots.at(pp->locallab.selspot).vart = vart->getIntValue(); + pp->locallab.spots.at(pp->locallab.selspot).chrrt = chrrt->getValue(); + pp->locallab.spots.at(pp->locallab.selspot).neigh = neigh->getValue(); + pp->locallab.spots.at(pp->locallab.selspot).vart = vart->getValue(); pp->locallab.spots.at(pp->locallab.selspot).dehaz = dehaz->getIntValue(); pp->locallab.spots.at(pp->locallab.selspot).sensih = sensih->getIntValue(); pp->locallab.spots.at(pp->locallab.selspot).localTgaincurve = cTgainshape->getCurve(); @@ -3629,9 +3629,9 @@ void Locallab::setDefaults(const ProcParams * defParams, const ParamsEdited * pe amount->setDefault(defSpot->amount); // Retinex str->setDefault(defSpot->str); - chrrt->setDefault((double)defSpot->chrrt); - neigh->setDefault((double)defSpot->neigh); - vart->setDefault((double)defSpot->vart); + chrrt->setDefault(defSpot->chrrt); + neigh->setDefault(defSpot->neigh); + vart->setDefault(defSpot->vart); dehaz->setDefault((double)defSpot->dehaz); sensih->setDefault((double)defSpot->sensih); softradiusret->setDefault(defSpot->softradiusret);