From fd43ed28fe055d9e125b83fb5d1630ebad45b708 Mon Sep 17 00:00:00 2001 From: Desmis Date: Sun, 5 Jul 2020 08:33:40 +0200 Subject: [PATCH] change exposure with Laplacian --- rtdata/languages/default | 4 ++-- rtengine/improcfun.h | 2 +- rtengine/iplocallab.cc | 52 +++++++++++++++++++++++++++++++++------- rtengine/procparams.cc | 2 +- rtgui/locallabtools.cc | 2 +- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/rtdata/languages/default b/rtdata/languages/default index 7ce5b4f3f..2457b83ee 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -2492,13 +2492,13 @@ TP_LOCALLAB_EXPLAP_TOOLTIP;The more you act on this threshold slider, the greate TP_LOCALLAB_EXPMERGEFILE_TOOLTIP;Allows various possibilities to blend image (as layers in Photosshop) : difference, multiply, soft light, overlay...with opacity...\nOriginal Image : merge current RT-spot with Original.\nPrevious spot : merge current Rt-spot with previous - if there is only one spot previous = original.\nBackground : merge current RT-spot with a color and luminance background (less possibilties) TP_LOCALLAB_EXPMETHOD_TOOLTIP;Standard : use an algorithm similar as main Exposure but in L*a*b* and taking account of deltaE.\n\nLaplacian & PDE : use another algorithm also with deltaE and with Poisson equation to solve Laplacian in Fourier space.\nPDE IPOL, PDE Fattal and Standard can be combined.\nFFTW Fourier Transform is optimized in size to reduce processing time.\nPDE reduce artifacts and noise. TP_LOCALLAB_EXPNOISEMETHOD_TOOLTIP;Apply a median before Laplace transform to prevent artifacts (noise).\nYou can also use "Denoise" tool. -TP_LOCALLAB_EXPOSE;Exposure - PDE algorithms +TP_LOCALLAB_EXPOSE;PDE algorithms & Exposure TP_LOCALLAB_EXPOSURE_TOOLTIP;In some cases (strong shadows ..) you can use others modules "Shadows Highlights", "Tone equalizer", "TRC", "Encoding Log"... TP_LOCALLAB_EXPRETITOOLS;Advanced Retinex Tools TP_LOCALLAB_EXPSHARP_TOOLTIP;RT-Spot minimum 39*39.\nUse low transition values and high decay transition values and scope to simulate small RT-spot. TP_LOCALLAB_EXPTOOL;Tools exposure TP_LOCALLAB_EXPTRC;Tone Response Curve - TRC -TP_LOCALLAB_EXP_TOOLNAME;Exposure - Dynamic Range Compression - 10 +TP_LOCALLAB_EXP_TOOLNAME;Laplacian PDE -Dynamic Range Compression & Exposure- 10 TP_LOCALLAB_FATAMOUNT;Amount TP_LOCALLAB_FATANCHOR;Anchor TP_LOCALLAB_FATANCHORA;Offset diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 57c8c4c64..66ad4dc57 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -351,7 +351,7 @@ public: void transit_shapedetect_retinex(int call, int senstype, LabImage * bufexporig, LabImage * bufmask, LabImage * buforigmas, float **buflight, float **bufchro, const float hueref, const float chromaref, const float lumaref, const struct local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk); void transit_shapedetect(int senstype, const LabImage *bufexporig, LabImage * originalmask, float **bufchro, bool HHutili, const float hueref, const float chromaref, const float lumaref, float sobelref, float meansobel, float ** blend2, const struct local_params & lp, LabImage * original, LabImage * transformed, int cx, int cy, int sk); - void exlabLocal(local_params& lp, int bfh, int bfw, LabImage* bufexporig, LabImage* lab, const LUTf& hltonecurve, const LUTf& shtonecurve, const LUTf& tonecurve); + void exlabLocal(local_params& lp, int bfh, int bfw, int bfhr, int bfwr, LabImage* bufexporig, LabImage* lab, const LUTf& hltonecurve, const LUTf& shtonecurve, const LUTf& tonecurve, const float hueref, const float lumaref, const float chromaref); void Exclude_Local(float **deltaso, float hueref, float chromaref, float lumaref, float sobelref, float meansobel, const struct local_params & lp, const LabImage * original, LabImage * transformed, const LabImage * rsv, const LabImage * reserv, int cx, int cy, int sk); void DeNoise_Local(int call, const struct local_params& lp, LabImage* originalmask, int levred, float hueref, float lumaref, float chromaref, LabImage* original, LabImage* transformed, const LabImage &tmp1, int cx, int cy, int sk); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 9b982cd84..ca65f3779 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -2405,7 +2405,7 @@ void ImProcFunctions::softprocess(const LabImage* bufcolorig, array2D &bu } } -void ImProcFunctions::exlabLocal(local_params& lp, int bfh, int bfw, LabImage* bufexporig, LabImage* lab, const LUTf& hltonecurve, const LUTf& shtonecurve, const LUTf& tonecurve) +void ImProcFunctions::exlabLocal(local_params& lp, int bfh, int bfw, int bfhr, int bfwr, LabImage* bufexporig, LabImage* lab, const LUTf& hltonecurve, const LUTf& shtonecurve, const LUTf& tonecurve, const float hueref, const float lumaref, const float chromaref) { BENCHFUN //exposure local @@ -2422,8 +2422,42 @@ void ImProcFunctions::exlabLocal(local_params& lp, int bfh, int bfw, LabImage* b if (lp.linear > 0.f && lp.expcomp == 0.f) { lp.expcomp = 0.001f; } + bool exec = (lp.expmet == 1 && lp.linear > 0.f && lp.laplacexp > 0.1f && !lp.invex); - if (lp.expmet == 1 && lp.linear > 0.f && lp.laplacexp > 0.1f && !lp.invex) { + //Laplacian PDE before exposure to smooth L, algorithm exposure leads to increase L differences + const std::unique_ptr datain(new float[bfwr * bfhr]); + const std::unique_ptr dataout(new float[bfwr * bfhr]); + const std::unique_ptr dE(new float[bfwr * bfhr]); + + + if(!exec) { + float diffde = 100.f - lp.sensex;//the more scope, the less take into account dE for Laplace + deltaEforLaplace(dE.get(), diffde, bfwr, bfhr, bufexporig, hueref, chromaref, lumaref); + +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) if (multiThread) +#endif + for (int y = 0; y < bfhr; y++) { + for (int x = 0; x < bfwr; x++) { + datain[y * bfwr + x] = bufexporig->L[y][x]; + } + } + + MyMutex::MyLock lock(*fftwMutex); + ImProcFunctions::retinex_pde(datain.get(), dataout.get(), bfwr, bfhr, 360.f, 1.f, dE.get(), 0, 1, 1);//350 arbitrary value about 45% strength Laplacian +#ifdef _OPENMP + #pragma omp parallel for schedule(dynamic,16) if (multiThread) +#endif + for (int y = 0; y < bfhr; y++) { + for (int x = 0; x < bfwr; x++) { + bufexporig->L[y][x] = dataout[y * bfwr + x]; + } + } + } + + + + if (exec) { #ifdef _OPENMP #pragma omp parallel for if (multiThread) @@ -2432,7 +2466,7 @@ void ImProcFunctions::exlabLocal(local_params& lp, int bfh, int bfw, LabImage* b for (int jr = 0; jr < bfw; jr++) { float L = bufexporig->L[ir][jr]; const float Llin = LIM01(L / 32768.f); - const float addcomp = linear * (-kl * Llin + kl);//maximum about 1. IL + const float addcomp = linear * (-kl * Llin + kl);//maximum about 1 . IL const float exp_scale = pow_F(2.0, (lp.expcomp + addcomp)); const float shoulder = ((maxran / rtengine::max(1.0f, exp_scale)) * hlcompthr) + 0.1f; const float comp = (rtengine::max(0.f, (lp.expcomp + addcomp)) + 1.f) * hlcomp; @@ -2451,8 +2485,8 @@ void ImProcFunctions::exlabLocal(local_params& lp, int bfh, int bfw, LabImage* b #ifdef _OPENMP #pragma omp parallel for if (multiThread) #endif - for (int ir = 0; ir < bfh; ir++) { - for (int jr = 0; jr < bfw; jr++) { + for (int ir = 0; ir < bfhr; ir++) { + for (int jr = 0; jr < bfwr; jr++) { float L = bufexporig->L[ir][jr]; //highlight const float hlfactor = (2 * L < MAXVALF ? hltonecurve[2 * L] : CurveFactory::hlcurve(cexp_scale, ccomp, chlrange, 2 * L)); @@ -5253,7 +5287,7 @@ void ImProcFunctions::InverseColorLight_Local(bool tonequ, bool tonecurv, int sp } } else if (senstype == 1) { //exposure - ImProcFunctions::exlabLocal(lp, GH, GW, original, temp.get(), hltonecurveloc, shtonecurveloc, tonecurveloc); + ImProcFunctions::exlabLocal(lp, GH, GW, GW, GH, original, temp.get(), hltonecurveloc, shtonecurveloc, tonecurveloc, hueref, lumaref, chromaref); if (exlocalcurve) { #ifdef _OPENMP @@ -12942,7 +12976,7 @@ void ImProcFunctions::Lab_Local( if (bfw >= mSP && bfh >= mSP) { - if (lp.expmet == 1) { + if (lp.expmet == 1 || lp.expmet == 0) { optfft(N_fftwsize, bfh, bfw, bfhr, bfwr, lp, original->H, original->W, xstart, ystart, xend, yend, cx, cy); } @@ -13096,12 +13130,12 @@ void ImProcFunctions::Lab_Local( lp.expcomp = 0.001f; // to enabled } - ImProcFunctions::exlabLocal(lp, bfh, bfw, bufexpfin.get(), bufexpfin.get(), hltonecurveloc, shtonecurveloc, tonecurveloc); + ImProcFunctions::exlabLocal(lp, bfh, bfw, bfhr, bfwr, bufexpfin.get(), bufexpfin.get(), hltonecurveloc, shtonecurveloc, tonecurveloc, hueref, lumaref, chromaref); } else { - ImProcFunctions::exlabLocal(lp, bfh, bfw, bufexporig.get(), bufexpfin.get(), hltonecurveloc, shtonecurveloc, tonecurveloc); + ImProcFunctions::exlabLocal(lp, bfh, bfw, bfhr, bfwr, bufexporig.get(), bufexpfin.get(), hltonecurveloc, shtonecurveloc, tonecurveloc, hueref, lumaref, chromaref); } //gradient diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index deeae9c54..d177e44a2 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -2869,7 +2869,7 @@ LocallabParams::LocallabSpot::LocallabSpot() : expexpose(false), complexexpose(0), expcomp(0.0), - hlcompr(0), + hlcompr(20), hlcomprthresh(0), black(0), shadex(0), diff --git a/rtgui/locallabtools.cc b/rtgui/locallabtools.cc index 1dd5513da..8deff0170 100644 --- a/rtgui/locallabtools.cc +++ b/rtgui/locallabtools.cc @@ -2191,7 +2191,7 @@ LocallabExposure::LocallabExposure(): exptoolexp(Gtk::manage(new MyExpander(false, M("TP_LOCALLAB_EXPTOOL")))), expcomp(Gtk::manage(new Adjuster(M("TP_EXPOSURE_EXPCOMP"), MINEXP, MAXEXP, 0.01, 0.))), black(Gtk::manage(new Adjuster(M("TP_EXPOSURE_BLACKLEVEL"), -16384, 32768, 10, 0))), - hlcompr(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTS"), 0, 500, 1, 0))), + hlcompr(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTS"), 0, 500, 1, 20))), hlcomprthresh(Gtk::manage(new Adjuster(M("TP_EXPOSURE_COMPRHIGHLIGHTSTHRESHOLD"), 0, 100, 1, 0))), shadex(Gtk::manage(new Adjuster(M("TP_LOCALLAB_SHADEX"), 0, 100, 1, 0))), shcompr(Gtk::manage(new Adjuster(M("TP_LOCALLAB_SHADEXCOMP"), 0, 100, 1, 50))),