From 7ba7869952a744c3c0889bb76ad9bae65dd475ee Mon Sep 17 00:00:00 2001 From: Desmis Date: Fri, 4 Oct 2019 16:42:00 +0200 Subject: [PATCH] enabled mask after Tone mapping --- rtengine/improcfun.h | 2 ++ rtengine/iplocallab.cc | 36 ++++++++++++++++++++---------------- rtengine/ipretinex.cc | 34 ++++++++++++++++++++-------------- rtgui/locallab.cc | 2 +- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index d63f0d4be..c0a59d746 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -193,6 +193,8 @@ public: void fftw_convol_blur(float *input, float *output, int bfw, int bfh, float radius, int fftkern, int algo); void fftw_convol_blur2(float **input2, float **output2, int bfw, int bfh, float radius, int fftkern, int algo); void fftw_tile_blur(int GW, int GH, int tilssize , int max_numblox_W, int min_numblox_W, float **tmp1, int numThreads, double radius); + void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_L, int H_L, int skip, const LocCCmaskCurve & locccmasretiCurve, bool &lcmasretiutili, const LocLLmaskCurve & locllmasretiCurve, bool &llmasretiutili, const LocHHmaskCurve & lochhmasretiCurve, bool & lhmasretiutili, int llretiMask, bool retiMasktmap, bool retiMask, + float rad, float gamm, float slop, float chro, float blend, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, bool multiThread); void MSRLocal(int sp, bool fftw, int lum, float** reducDE, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, float** luminance, float** templ, const float* const *originalLuminance, const int width, const int height, int bfwr, int bfhr, const procparams::LocallabParams &loc, const int skip, const LocretigainCurve &locRETgainCcurve, const LocretitransCurve &locRETtransCcurve, const int chrome, const int scall, const float krad, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax, const LocCCmaskCurve & locccmasretiCurve, bool &lcmasretiutili, const LocLLmaskCurve & locllmasretiCurve, bool &llmasretiutili, const LocHHmaskCurve & lochhmasretiCurve, bool & lhmasretiutili, int llretiMask, LabImage * transformed, bool retiMasktmap, bool retiMask); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 442471907..d02d51ee3 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -2300,10 +2300,12 @@ static void blendmask(const local_params& lp, int xstart, int ystart, int cx, in } case 2: { - - original->L[y + ystart][x + xstart] = bufexporig->L[y][x]; - original->a[y + ystart][x + xstart] = bufexporig->a[y][x]; - original->b[y + ystart][x + xstart] = bufexporig->b[y][x]; + original->L[y + ystart][x + xstart] += (bl * bufmaskor->L[y][x]); + original->a[y + ystart][x + xstart] *= (1.f + bl * bufmaskor->a[y][x]); + original->b[y + ystart][x + xstart] *= (1.f + bl * bufmaskor->b[y][x]); + original->L[y + ystart][x + xstart] = CLIP(original->L[y + ystart][x + xstart]); + original->a[y + ystart][x + xstart] = CLIPC(original->a[y + ystart][x + xstart]); + original->b[y + ystart][x + xstart] = CLIPC(original->b[y + ystart][x + xstart]); } } @@ -2453,6 +2455,7 @@ void maskcalccol(int bfw, int bfh, int xstart, int ystart, int sk, int cx, int c array2D guid(bfw, bfh); float meanfab, fab; mean_fab(xstart, ystart, bfw, bfh, bufcolorig, original, fab, meanfab, chrom); + meanfab = 5000.f; if (deltaE || modmask || enaMask || showmaske) { @@ -7473,14 +7476,11 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o std::unique_ptr bufmaskorigtm; std::unique_ptr bufmaskblurtm; std::unique_ptr originalmasktm; - LabImage *orimask = nullptr; - orimask = new LabImage(original->W, original->H); if (lp.showmasktmmet == 0 || lp.showmasktmmet == 2 || lp.enatmMask || lp.showmasktmmet == 3 || lp.showmasktmmet == 4) { bufmaskorigtm.reset(new LabImage(bfw, bfh)); bufmaskblurtm.reset(new LabImage(bfw, bfh)); originalmasktm.reset(new LabImage(bfw, bfh)); - orimask->CopyFrom(original); } int itera = 0; @@ -7560,24 +7560,25 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o ImProcFunctions::EPDToneMaplocal(sp, bufgb.get(), tmp1.get(), itera, sk);//iterate to 0 calculate with edgstopping, improve result, call=1 dcrop we can put iterate to 5 - tmp1m->CopyFrom(tmp1.get()); + tmp1m->CopyFrom(tmp1.get());//save current result + bool enatmMasktmap = params->locallab.spots.at(sp).enatmMaskaft; - if (params->locallab.spots.at(sp).enatmMaskaft) { - - maskcalccol(bfw, bfh, xstart, ystart, sk, cx, cy, tmp1m.get(), bufmaskorigtm.get(), originalmasktm.get(), orimask, transformed, inv, lp, + if (enatmMasktmap) { + //calculate new values for original, originalmasktm, bufmaskorigtm...in function of tmp1 + maskcalccol(bfw, bfh, xstart, ystart, sk, cx, cy, tmp1.get(), bufmaskorigtm.get(), originalmasktm.get(), original, transformed, inv, lp, locccmastmCurve, lcmastmutili, locllmastmCurve, llmastmutili, lochhmastmCurve, lhmastmutili, multiThread, enaMask, showmaske, deltaE, modmask, zero, modif, chrom, rad, gamma, slope, blendm); - if (lp.showmasktmmet == 3) { - showmask(lp, xstart, ystart, cx, cy, bfw, bfh, tmp1m.get(), transformed, bufmaskorigtm.get(), 0); + if (lp.showmasktmmet == 3) {//dispaly mask + showmask(lp, xstart, ystart, cx, cy, bfw, bfh, tmp1.get(), transformed, bufmaskorigtm.get(), 0); return; } - original->CopyFrom(orimask); } - delete orimask; + tmp1->CopyFrom(tmp1m.get());//restore current result + float minL = tmp1->L[0][0] - bufgb->L[0][0]; float maxL = minL; @@ -7631,8 +7632,11 @@ void ImProcFunctions::Lab_Local(int call, int sp, float** shbuffer, LabImage * o } } */ - bufgb.reset(); + // + // transit_shapedetect_retinex(call, 4, bufgb.get(),bufmaskorigtm.get(), originalmasktm.get(), buflight, bufchro, hueref, chromaref, lumaref, lp, original, transformed, cx, cy, sk); + transit_shapedetect(8, tmp1.get(), originalmasktm.get(), buflight, bufchro, nullptr, nullptr, nullptr, false, hueref, chromaref, lumaref, sobelref, 0.f, nullptr, lp, original, transformed, cx, cy, sk); + bufgb.reset(); } } } diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index 3fda30b7b..eb5b99b7c 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -851,8 +851,8 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e } -void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_L, int H_L, int skip, const LocCCmaskCurve & locccmasretiCurve, bool &lcmasretiutili, const LocLLmaskCurve & locllmasretiCurve, bool &llmasretiutili, const LocHHmaskCurve & lochhmasretiCurve, bool & lhmasretiutili, int llretiMask, bool retiMasktmap, bool retiMask, - const LocallabParams &loc, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, bool multiThread) +void ImProcFunctions::maskforretinex(int sp, int before, float ** luminance, float ** out, int W_L, int H_L, int skip, const LocCCmaskCurve & locccmasretiCurve, bool &lcmasretiutili, const LocLLmaskCurve & locllmasretiCurve, bool &llmasretiutili, const LocHHmaskCurve & lochhmasretiCurve, bool & lhmasretiutili, int llretiMask, bool retiMasktmap, bool retiMask, + float rad, float gamm, float slop, float chro, float blend, LabImage * bufreti, LabImage * bufmask, LabImage * buforig, LabImage * buforigmas, bool multiThread) { array2D loctemp(W_L, H_L); array2D ble(W_L, H_L); @@ -876,6 +876,7 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ } } } + printf("OK 2\n"); float fab = 4000.f;//value must be good in most cases @@ -892,6 +893,7 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ if (locllmasretiCurve && llmasretiutili) { float ligh = loctemp[ir][jr] / 32768.f; kmaskLexp = 32768.f * LIM01(1.f - locllmasretiCurve[500.f * ligh]); + } @@ -931,14 +933,14 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ } } + printf("OK 3\n"); - - if (loc.spots.at(sp).radmaskreti > 0.f) { - guidedFilter(guid, ble, ble, loc.spots.at(sp).radmaskreti * 10.f / skip, 0.001, multiThread, 4); + if (rad > 0.f) { + guidedFilter(guid, ble, ble, rad * 10.f / skip, 0.001, multiThread, 4); } LUTf lutTonemaskreti(65536); - calcGammaLut(loc.spots.at(sp).gammaskreti, loc.spots.at(sp).slomaskreti, lutTonemaskreti); + calcGammaLut(gamm, slop, lutTonemaskreti); float radiusb = 1.f / skip; #ifdef _OPENMP @@ -960,11 +962,11 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ #endif { gaussianBlur(bufmaskblurreti->L, bufmaskorigreti->L, W_L, H_L, radiusb); - gaussianBlur(bufmaskblurreti->a, bufmaskorigreti->a, W_L, H_L, 1.f + (0.5f * loc.spots.at(sp).radmaskreti) / skip); - gaussianBlur(bufmaskblurreti->b, bufmaskorigreti->b, W_L, H_L, 1.f + (0.5f * loc.spots.at(sp).radmaskreti) / skip); + gaussianBlur(bufmaskblurreti->a, bufmaskorigreti->a, W_L, H_L, 1.f + (0.5f * rad) / skip); + gaussianBlur(bufmaskblurreti->b, bufmaskorigreti->b, W_L, H_L, 1.f + (0.5f * rad) / skip); } - float modr = 0.01f * (float) loc.spots.at(sp).blendmaskreti; + float modr = 0.01f * (float) blend; if (llretiMask != 3 && retiMask) { #ifdef _OPENMP @@ -982,8 +984,8 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ } - bufreti->a[y][x] *= (1.f + bufmaskorigreti->a[y][x] * modr * (1.f + 0.01f * loc.spots.at(sp).chromaskreti)); - bufreti->b[y][x] *= (1.f + bufmaskorigreti->b[y][x] * modr * (1.f + 0.01f * loc.spots.at(sp).chromaskreti)); + bufreti->a[y][x] *= (1.f + bufmaskorigreti->a[y][x] * modr * (1.f + 0.01f * chro)); + bufreti->b[y][x] *= (1.f + bufmaskorigreti->b[y][x] * modr * (1.f + 0.01f * chro)); bufreti->a[y][x] = CLIPC(bufreti->a[y][x]); bufreti->b[y][x] = CLIPC(bufreti->b[y][x]); } @@ -1029,6 +1031,7 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ if (llretiMask == 3) { + printf("OK 4\n"); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,16) @@ -1041,7 +1044,6 @@ void maskforretinex(int sp, int before, float ** luminance, float ** out, int W_ bufmask->b[y][x] = CLIPC(bufreti->b[y][x] * bufmaskorigreti->b[y][x]); } } - } } @@ -1568,13 +1570,17 @@ void ImProcFunctions::MSRLocal(int sp, bool fftw, int lum, float** reducDE, LabI } } + float rad = loc.spots.at(sp).radmaskreti; + float slop = loc.spots.at(sp).slomaskreti; + float gamm = loc.spots.at(sp).gammaskreti; + float blend = loc.spots.at(sp).blendmaskreti; + float chro = loc.spots.at(sp).chromaskreti; if (lum == 1 && (llretiMask == 3 || llretiMask == 0 || llretiMask == 2 || llretiMask == 4)) { //only mask with luminance on last scale int before = 1; maskforretinex(sp, before, luminance, nullptr, W_L, H_L, skip, locccmasretiCurve, lcmasretiutili, locllmasretiCurve, llmasretiutili, lochhmasretiCurve, lhmasretiutili, llretiMask, retiMasktmap, retiMask, - loc, bufreti, bufmask, buforig, buforigmas, multiThread); + rad, gamm, slop, chro, blend , bufreti, bufmask, buforig, buforigmas, multiThread); } - //mask does not interfered with datas displayed Tmean = mean; diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index b8c35924e..1b83d3ec7 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -1274,7 +1274,7 @@ Locallab::Locallab(): ToolParamBlock* const masktmBox = Gtk::manage(new ToolParamBlock()); masktmBox->pack_start(*showmasktmMethod, Gtk::PACK_SHRINK, 4); masktmBox->pack_start(*enatmMask, Gtk::PACK_SHRINK, 0); -// masktmBox->pack_start(*enatmMaskaft, Gtk::PACK_SHRINK, 0); + masktmBox->pack_start(*enatmMaskaft, Gtk::PACK_SHRINK, 0); masktmBox->pack_start(*masktmCurveEditorG, Gtk::PACK_SHRINK, 4); // Padding is mandatory to correct behavior of curve editor masktmBox->pack_start(*blendmasktm, Gtk::PACK_SHRINK, 0); masktmBox->pack_start(*radmasktm, Gtk::PACK_SHRINK, 0);