From 289ff4dcad5ce037a18d075cdf16784912ca6fc7 Mon Sep 17 00:00:00 2001 From: Desmis Date: Wed, 28 Aug 2019 19:55:03 +0200 Subject: [PATCH] another improvment to Guidedfilter wavelet - all linear --- rtengine/improcfun.h | 2 +- rtengine/iplocallab.cc | 122 +++++++++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 35 deletions(-) diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 5ffdf59b5..a0b2a53d0 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -255,7 +255,7 @@ public: void chromiLuminanceCurve(PipetteBuffer *pipetteBuffer, int pW, LabImage* lold, LabImage* lnew, LUTf &acurve, LUTf &bcurve, LUTf & satcurve, LUTf & satclcurve, LUTf &clcurve, LUTf &curve, bool utili, bool autili, bool butili, bool ccutili, bool cclutili, bool clcutili, LUTu &histCCurve, LUTu &histLurve); void vibrance(LabImage* lab, const procparams::VibranceParams &vibranceParams, bool highlight, const Glib::ustring &workingProfile); //Jacques' vibrance void softprocess(const LabImage* bufcolorig, array2D &buflight, /* float ** bufchro, float ** buf_a, float ** buf_b, */ float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread); - void softproc(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread); + void softproc(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread, int flag); // void colorCurve (LabImage* lold, LabImage* lnew); void sharpening(LabImage* lab, const procparams::SharpeningParams &sharpenParam, bool showMask = false); void sharpeningcam(CieImage* ncie, float** buffer, bool showMask = false); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 889295633..fa89d7eb0 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -3,6 +3,7 @@ * * Copyright (c) 2004-2010 Gabor Horvath * + * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -1253,45 +1254,96 @@ void ImProcFunctions::ciecamloc_02float(int sp, LabImage* lab) } } -void ImProcFunctions::softproc(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread) +void ImProcFunctions::softproc(const LabImage* bufcolorig, const LabImage* bufcolfin, float rad, int bfh, int bfw, double epsilmax, double epsilmin, float thres, int sk, bool multiThread, int flag) { - if (rad > 0.f) { - array2D ble(bfw, bfh); - array2D guid(bfw, bfh); + if (flag == 0) { + if (rad > 0.f) { + array2D ble(bfw, bfh); + array2D guid(bfw, bfh); + Imagefloat *tmpImage = nullptr; + tmpImage = new Imagefloat(bfw, bfh); + #ifdef _OPENMP - #pragma omp parallel for + #pragma omp parallel for #endif - for (int ir = 0; ir < bfh; ir++) - for (int jr = 0; jr < bfw; jr++) { - float X, Y, Z; - float L = bufcolorig->L[ir][jr]; - float a = bufcolorig->a[ir][jr]; - float b = bufcolorig->b[ir][jr]; - Color::Lab2XYZ(L, a, b, X, Y, Z); + for (int ir = 0; ir < bfh; ir++) + for (int jr = 0; jr < bfw; jr++) { + float X, Y, Z; + float L = bufcolorig->L[ir][jr]; + float a = bufcolorig->a[ir][jr]; + float b = bufcolorig->b[ir][jr]; + Color::Lab2XYZ(L, a, b, X, Y, Z); - guid[ir][jr] = Y / 32768.f; + guid[ir][jr] = Y / 32768.f; + float La = bufcolfin->L[ir][jr]; + float aa = bufcolfin->a[ir][jr]; + float ba = bufcolfin->b[ir][jr]; + Color::Lab2XYZ(La, aa, ba, X, Y, Z); + tmpImage->r(ir, jr) = X; + tmpImage->g(ir, jr) = Y; + tmpImage->b(ir, jr) = Z; + ble[ir][jr] = Y / 32768.f; + } - ble[ir][jr] = (bufcolfin->L[ir][jr]) / 32768.f; - } + double aepsil = (epsilmax - epsilmin) / 90.f; + double bepsil = epsilmax - 100.f * aepsil; + double epsil = aepsil * rad + bepsil; - double aepsil = (epsilmax - epsilmin) / 90.f; - double bepsil = epsilmax - 100.f * aepsil; - double epsil = aepsil * rad + bepsil; - - float blur = 10.f / sk * (thres + 0.8f * rad); - rtengine::guidedFilter(guid, ble, ble, blur, epsil, multiThread, 4); + float blur = 10.f / sk * (thres + 0.8f * rad); + rtengine::guidedFilter(guid, ble, ble, blur, epsil, multiThread, 4); #ifdef _OPENMP - #pragma omp parallel for + #pragma omp parallel for #endif - for (int ir = 0; ir < bfh; ir++) - for (int jr = 0; jr < bfw; jr++) { - bufcolfin->L[ir][jr] = 32768.f * ble[ir][jr]; - } + for (int ir = 0; ir < bfh; ir++) + for (int jr = 0; jr < bfw; jr++) { + float X = tmpImage->r(ir, jr); + float Y = 32768.f * ble[ir][jr]; + float Z = tmpImage->b(ir, jr); + float L, a, b; + Color::XYZ2Lab(X, Y, Z, L, a, b); + bufcolfin->L[ir][jr] = L; + } + + delete tmpImage; + } + } else if (flag == 1) { + if (rad > 0.f) { + array2D ble(bfw, bfh); + array2D guid(bfw, bfh); +#ifdef _OPENMP + #pragma omp parallel for +#endif + + for (int ir = 0; ir < bfh; ir++) + for (int jr = 0; jr < bfw; jr++) { + ble[ir][jr] = (bufcolfin->L[ir][jr]) / 32768.f; + guid[ir][jr] = bufcolorig->L[ir][jr] / 32768.f; + } + + double aepsil = (epsilmax - epsilmin) / 90.f; + double bepsil = epsilmax - 100.f * aepsil; + double epsil = aepsil * rad + bepsil; + + float blur = 10.f / sk * (thres + 0.8f * rad); + rtengine::guidedFilter(guid, ble, ble, blur, epsil, multiThread, 4); + + + +#ifdef _OPENMP + #pragma omp parallel for +#endif + + for (int ir = 0; ir < bfh; ir++) + for (int jr = 0; jr < bfw; jr++) { + bufcolfin->L[ir][jr] = 32768.f * ble[ir][jr]; + } + } + } } @@ -5765,7 +5817,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o double thresM = 0.05 * lp.epsb; double thresm = 0.01 * lp.epsb; - softproc(bufgb.get(), tmp1.get(), 3.f * lp.guidb, bfh, bfw, thresM, thresm, 0.1f, sk, multiThread); + softproc(bufgb.get(), tmp1.get(), 3.f * lp.guidb, bfh, bfw, thresM, thresm, 0.1f, sk, multiThread, 0); } } else if (lp.blurmet == 1 && lp.blmet == 2) { @@ -5784,7 +5836,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o double thresM = 0.05 * lp.epsb; double thresm = 0.01 * lp.epsb; - softproc(tmp2.get(), tmp1.get(), 3.f * lp.guidb, GH, GW, thresM, thresm, 0.1f, sk, multiThread); + softproc(tmp2.get(), tmp1.get(), 3.f * lp.guidb, GH, GW, thresM, thresm, 0.1f, sk, multiThread, 0); } } @@ -6989,7 +7041,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o ImProcFunctions::cbdl_local_temp(bufsh, loctemp->L, bfw, bfh, lp.mulloc, 1.f, lp.threshol, lp.clarityml, lp.contresid, lp.blurcbdl, skinprot, false, b_l, t_l, t_r, b_r, choice, sk, multiThread); if (lp.softradiuscb > 0.f) { - softproc(origcbdl.get(), loctemp.get(), lp.softradiuscb, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread); + softproc(origcbdl.get(), loctemp.get(), lp.softradiuscb, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread, 0); } } @@ -8045,15 +8097,17 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o wdspot.reconstruct(tmp1->data, 1.f); float thr = 0.001f; - + int flag = 0; if (maxlvl <= 4) { mL0 = 0.f; mL = -mL; - thr = 0.01f; + thr = 1.f; + flag = 0; } else { mL0 = mL; thr = 1.f; + flag = 0; } if (mL != 0.f) { @@ -8067,7 +8121,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } if (softr > 0.f) { - softproc(tmpres.get(), tmp1.get(), softr, bfh, bfw, 0.0001, 0.00001, thr, sk, multiThread); + softproc(tmpres.get(), tmp1.get(), softr, bfh, bfw, 0.0001, 0.00001, thr, sk, multiThread, flag); } } } @@ -8945,7 +8999,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } if (lp.softradiusexp > 0.f) { - softproc(bufexporig.get(), bufexpfin.get(), lp.softradiusexp, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread); + softproc(bufexporig.get(), bufexpfin.get(), lp.softradiusexp, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread, 0); // softprocess(bufexporig.get(), buflight, lp.softradiusexp, bfh, bfw, sk, multiThread); } @@ -9367,7 +9421,7 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } if (lp.softradiuscol > 0.f) { - softproc(bufcolorig.get(), bufcolfin.get(), lp.softradiuscol, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread); + softproc(bufcolorig.get(), bufcolfin.get(), lp.softradiuscol, bfh, bfw, 0.0001, 0.00001, 0.1f, sk, multiThread, 0); // softprocess(bufcolorig.get(), buflight, lp.softradiuscol, bfh, bfw, sk, multiThread); }