From f656d6f7b02852ef41ef135d05177492c22178f5 Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 30 Jun 2019 14:08:57 +0200 Subject: [PATCH] Change some settings and Retinex GUI radius --- rtengine/iplocallab.cc | 2 +- rtengine/ipretinex.cc | 1 + rtengine/procparams.cc | 2 +- rtgui/locallab.cc | 87 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 9f357d200..0195e48f8 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -6948,7 +6948,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o float minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax; bool fftw = lp.ftwreti; - ImProcFunctions::MSRLocal(sp, fftw, 1, bufreti, bufmask, buforig, buforigmas, orig, tmpl->L, orig1, Wd, Hd, params->locallab, sk, locRETgainCcurve, 0, 4, 0.8f, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax, + ImProcFunctions::MSRLocal(sp, fftw, 1, bufreti, bufmask, buforig, buforigmas, orig, tmpl->L, orig1, Wd, Hd, params->locallab, sk, locRETgainCcurve, 0, 4, 1.f, minCD, maxCD, mini, maxi, Tmean, Tsigma, Tmin, Tmax, locccmasretiCurve, lcmasretiutili, locllmasretiCurve, llmasretiutili, lochhmasretiCurve, lhmasretiutili, llretiMask, transformed, lp.enaretiMasktmap, lp.enaretiMask); diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index f15f99d6e..e0873502f 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -882,6 +882,7 @@ void ImProcFunctions::MSRLocal(int sp, bool fftw, int lum, LabImage * bufreti, L //empirical skip evaluation : very difficult because quasi all parameters interfere //to test on several images int nei = (int)(krad * loc.spots.at(sp).neigh); + // printf("neigh=%i\n", nei); //several test to find good values ???!!! //very difficult to do because 4 factor are correlate with skip and cannot been solved easily // size of spots diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 6ce1f2881..59bcf47cb 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -2474,7 +2474,7 @@ LocallabParams::LocallabSpot::LocallabSpot() : retinexMethod("high"), str(0.0), chrrt(0.0), - neigh(50.), + neigh(200.), vart(70.), dehaz(0), sensih(30), diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index daba5a1e4..47e037320 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -36,10 +36,93 @@ #define MINCHRO 0. #define MAXCHRO 150 #define MAXCHROCC 100 +#define MINNEIGH 4 +#define MAXNEIGH 5000 +#define CENTERNEIGH 200 using namespace rtengine; extern Options options; +static double retiSlider2neigh(double sval) +{ + + // slider range: 0 - 5000 + double neigh; + + if (sval <= 1000) { + // linear below center-temp + neigh = MINNEIGH + (sval / 1000.0) * (CENTERNEIGH - MINNEIGH); + } else { + const double slope = (double)(CENTERNEIGH - MINNEIGH) / (MAXNEIGH - CENTERNEIGH); + double x = (sval - 1000) / 1000; // x 0..1 + double y = x * slope + (1.0 - slope) * pow(x, 4.0); + neigh = CENTERNEIGH + y * (MAXNEIGH - CENTERNEIGH); + } + + if (neigh < MINNEIGH) { + neigh = MINNEIGH; + } + + if (neigh > MAXNEIGH) { + neigh = MAXNEIGH; + } + + return neigh; +} + +static double retiNeigh2Slider(double neigh) +{ + + double sval; + + if (neigh <= CENTERNEIGH) { + sval = ((neigh - MINNEIGH) / (CENTERNEIGH - MINNEIGH)) * 1000.0; + } else { + const double slope = (double)(CENTERNEIGH - MINNEIGH) / (MAXNEIGH - CENTERNEIGH); + const double y = (neigh - CENTERNEIGH) / (MAXNEIGH - CENTERNEIGH); + double x = pow(y, 0.25); // rough guess of x, will be a little lower + double k = 0.1; + bool add = true; + + // the y=f(x) function is a mess to invert, therefore we have this trial-refinement loop instead. + // from tests, worst case is about 20 iterations, ie no problem + for (;;) { + double y1 = x * slope + (1.0 - slope) * pow(x, 4.0); + + if (1000 * fabs(y1 - y) < 0.1) { + break; + } + + if (y1 < y) { + if (!add) { + k /= 2; + } + + x += k; + add = true; + } else { + if (add) { + k /= 2; + } + + x -= k; + add = false; + } + } + + sval = 1000.0 + x * 1000.0; + } + + if (sval < 0) { + sval = 0; + } + + if (sval > 5000) { + sval = 5000; + } + + return sval; +} Locallab::Locallab(): FoldableToolPanel(this, "locallab", M("TP_LOCALLAB_LABEL"), false, true), @@ -152,7 +235,9 @@ Locallab::Locallab(): // 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.0, 100.0, 0.1, 0.0))), - neigh(Gtk::manage(new Adjuster(M("TP_LOCALLAB_NEIGH"), 4., 1000., 0.5, 50.))), + neigh(Gtk::manage(new Adjuster(M("TP_LOCALLAB_NEIGH"), MINNEIGH, MAXNEIGH, 0.5, CENTERNEIGH, nullptr, nullptr, &retiSlider2neigh, &retiNeigh2Slider))), + + // neigh(Gtk::manage(new Adjuster(M("TP_LOCALLAB_NEIGH"), 4., 4000., 0.5, 50.))), vart(Gtk::manage(new Adjuster(M("TP_LOCALLAB_VART"), 4.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))),