From 53ba84f69934859193e52fcee7f8fdb507eb322b Mon Sep 17 00:00:00 2001 From: Desmis Date: Thu, 2 Nov 2017 13:19:16 +0100 Subject: [PATCH] Fixed some bugs and some changes --- rtengine/dcrop.cc | 6 +- rtengine/improccoordinator.cc | 49 +++++++++----- rtengine/improccoordinator.h | 3 +- rtengine/improcfun.h | 4 +- rtengine/iplocallab.cc | 120 +++++++++++++++++++++++++++++----- rtengine/procevents.h | 1 + rtengine/procparams.cc | 15 +++++ rtengine/procparams.h | 1 + rtengine/refreshmap.cc | 3 +- rtengine/simpleprocess.cc | 23 ++++--- rtgui/locallab.cc | 31 +++++++-- rtgui/locallab.h | 3 +- rtgui/paramsedited.cc | 6 ++ rtgui/paramsedited.h | 1 + 14 files changed, 210 insertions(+), 56 deletions(-) diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 13b3ff753..b32c24264 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -1149,10 +1149,11 @@ void Crop::update (int todo) params.locallab.hueref = (parent->huerefs[sp]) / 100.f; params.locallab.chromaref = parent->chromarefs[sp]; params.locallab.lumaref = parent->lumarefs[sp]; + params.locallab.sobelref = parent->sobelrefs[sp]; parent->ipf.Lab_Local (params.locallab, 1, sp, (float**)shbuffer, labnCrop, labnCrop, trafx / skip, trafy / skip, cropx / skip, cropy / skip, skips (parent->fw, skip), skips (parent->fh, skip), parent->fw, parent->fh, locutili, skip, locRETgainCurve, locallutili, lllocalcurve2, - loclhCurve, lochhCurve, LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref); + loclhCurve, lochhCurve, LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref, params.locallab.sobelref); lllocalcurve2.clear(); cclocalcurve2.clear(); sklocalcurve2.clear(); @@ -1524,8 +1525,9 @@ void Crop::update (int todo) params.locallab.hueref = (parent->huerefs[sp]) / 100.f; params.locallab.chromaref = parent->chromarefs[sp]; params.locallab.lumaref = parent->lumarefs[sp]; + params.locallab.sobelref = parent->sobelrefs[sp]; parent->ipf.Lab_Local (params.locallab, 1, sp, (float**)shbuffer, labnCrop, labnCrop, trafx / skip, trafy / skip, cropx / skip, cropy / skip, skips (parent->fw, skip), skips (parent->fh, skip), parent->fw, parent->fh, locutili, skip, locRETgainCurve, locallutili, lllocalcurve2, loclhCurve, lochhCurve, - LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref); + LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref, params.locallab.sobelref); lllocalcurve2.clear(); cclocalcurve2.clear(); diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 4b78960d2..a6d03a53a 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -200,9 +200,12 @@ ImProcCoordinator::ImProcCoordinator () huerefs (500, -100000.f), chromarefs (500, -100000.f), lumarefs (500, -100000.f), + sobelrefs (500, -100000.f), + huer (0), chromar (0), lumar (0), + sobeler (0), colourToningSatLimit (0.f), colourToningSatLimitOpacity (0.f), retistrsav (nullptr) /* @@ -842,7 +845,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) }; - int maxdata = 81;//78;//73 for 10011 + int maxdata = 82;//78;//73 for 10011 if (fic0) { //find current version mip @@ -886,7 +889,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) //initilize newues when first utilisation of Locallab. Prepare creation of Mip files for (int sp = 1; sp < maxspot; sp++) { // spots default int t_sp = sp; - int t_mipversion = 10014;//new value for each change + int t_mipversion = 10015;//new value for each change int t_circrad = 18; int t_locX = 250; int t_locY = 250; @@ -1552,7 +1555,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) std::string line; std::string spotline; int cont = 0; - int maxind = maxdata - 3 ; // + int maxind = maxdata - 4 ; // if (versionmip == 10000) { maxind = 49; @@ -1826,7 +1829,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) for (int sp = ns + 1 ; sp < maxspot; sp++) { // spots default int t_sp = sp; - int t_mipversion = 10014; + int t_mipversion = 10015; int t_circrad = 18; int t_locX = 250; int t_locY = 250; @@ -2040,7 +2043,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) std::string spotline2; int cont2 = 0; int ns2 = 0; - int maxin = maxdata - 3; //70 ;//64 + int maxin = maxdata - 4; //70 ;//64 while (getline (fich2, line2)) { spotline2 = line2; @@ -2116,9 +2119,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) //main algorithm for all spots for (int sp = 1; sp < maxspot; sp++) { //spots default - params.locallab.hueref = dataspot[maxdata - 3][sp] / 100.; - params.locallab.chromaref = dataspot[maxdata - 2][sp]; - params.locallab.lumaref = dataspot[maxdata - 1][sp]; + params.locallab.hueref = dataspot[maxdata - 4][sp] / 100.; + params.locallab.chromaref = dataspot[maxdata - 3][sp]; + params.locallab.lumaref = dataspot[maxdata - 2][sp]; + params.locallab.sobelref = dataspot[maxdata - 1][sp]; bool locutili = false; params.locallab.circrad = circrads[sp] = dataspot[2][sp]; params.locallab.locX = locx[sp] = dataspot[3][sp]; @@ -2562,19 +2566,24 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) sca); double huere, chromare, lumare; - ipf.calc_ref (3, sp, (float**)shbuffer, nprevl, nprevl, 0, 0, 0, 0, pW, pH, fw, fh, locutili, scale, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, cclocalcurve, sklocalcurve, huere, chromare, lumare); + double sobelre; + ipf.calc_ref (3, sp, (float**)shbuffer, nprevl, nprevl, 0, 0, 0, 0, pW, pH, fw, fh, locutili, scale, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, cclocalcurve, sklocalcurve, huere, chromare, lumare, sobelre); huer = huere; chromar = chromare; lumar = lumare ; + sobeler = sobelre; params.locallab.hueref = huer; params.locallab.chromaref = chromar; params.locallab.lumaref = lumar; - dataspot[maxdata - 3][sp] = huerefs[sp] = 100.f * params.locallab.hueref; - dataspot[maxdata - 2][sp] = chromarefs[sp] = params.locallab.chromaref; - dataspot[maxdata - 1][sp] = lumarefs[sp] = params.locallab.lumaref; + params.locallab.sobelref = sobeler; + + dataspot[maxdata - 4][sp] = huerefs[sp] = 100.f * params.locallab.hueref; + dataspot[maxdata - 3][sp] = chromarefs[sp] = params.locallab.chromaref; + dataspot[maxdata - 2][sp] = lumarefs[sp] = params.locallab.lumaref; + dataspot[maxdata - 1][sp] = sobelrefs[sp] = params.locallab.sobelref; //printf("sp=%i huerefsp=%f\n", sp, huerefs[sp]); ipf.Lab_Local (params.locallab, 3, sp, (float**)shbuffer, nprevl, nprevl, 0, 0, 0, 0, pW, pH, fw, fh, locutili, scale, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, lochhCurve, - LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref); + LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref, params.locallab.sobelref); lllocalcurve.clear(); cclocalcurve.clear(); sklocalcurve.clear(); @@ -2598,6 +2607,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) params.locallab.hueref = INFINITY; params.locallab.chromaref = INFINITY; params.locallab.lumaref = INFINITY; + params.locallab.sobelref = INFINITY; locallutili = false; sps[sp] = sp; @@ -3094,9 +3104,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) params.locallab.hueref = huerefs[sp] / 100.; params.locallab.chromaref = chromarefs[sp]; params.locallab.lumaref = lumarefs[sp]; + params.locallab.sobelref = sobelrefs[sp]; ipf.Lab_Local (params.locallab, 3, sp, (float**)shbuffer, nprevl, nprevl, 0, 0, 0, 0, pW, pH, fw, fh, locutili, scale, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, lochhCurve, LHutili, HHutili, cclocalcurve, - localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref ); + localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref, params.locallab.sobelref); lllocalcurve.clear(); cclocalcurve.clear(); sklocalcurve.clear(); @@ -3111,7 +3122,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) for (int spe = 1; spe < maxspot; spe++) { int t_sp = spe; - int t_mipversion = 10014; + int t_mipversion = 10015; int t_circrad = dataspot[2][spe]; int t_locX = dataspot[3][spe]; int t_locY = dataspot[4][spe]; @@ -3195,9 +3206,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) int t_blurMethod = dataspot[76][spe]; int t_dustMethod = dataspot[77][spe]; - int t_hueref = dataspot[maxdata - 3][spe]; - int t_chromaref = dataspot[maxdata - 2][spe]; - int t_lumaref = dataspot[maxdata - 1][spe]; + int t_hueref = dataspot[maxdata - 4][spe]; + int t_chromaref = dataspot[maxdata - 3][spe]; + int t_lumaref = dataspot[maxdata - 2][spe]; + int t_sobelref = dataspot[maxdata - 1][spe]; @@ -3298,6 +3310,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) fou << "hueref=" << t_hueref << '@' << endl; fou << "chromaref=" << t_chromaref << '@' << endl; fou << "lumaref=" << t_lumaref << '@' << endl; + fou << "sobelref=" << t_sobelref << '@' << endl; fou << "curveReti=" << t_curvret << endl; fou << "curveLL=" << t_curvll << endl; fou << "curveLH=" << t_curvlh << endl; diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index 9939c5c85..b6fc465fc 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -350,8 +350,9 @@ protected: LUTf huerefs; LUTf chromarefs; LUTf lumarefs; + LUTf sobelrefs; - double huer, chromar, lumar; + double huer, chromar, lumar, sobeler; void startProcessing (); void process (); float colourToningSatLimit; diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index c0cda4b71..efc161894 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -292,10 +292,10 @@ public: int pitch, int scale, const int luma, const int chroma/*, LUTf & Lcurve, LUTf & abcurve*/ ); //locallab void MSRLocal (float** luminance, float** templ, const float* const *originalLuminance, const int width, const int height, const LocallabParams &loc, const int skip, const LocretigainCurve &locRETgainCcurve, 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); - void calc_ref (int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, LUTf & cclocalcurve, LUTf & sklocalcurve, double &huere, double &chromare, double &lumare); + void calc_ref (int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, LUTf & cclocalcurve, LUTf & sklocalcurve, double &huere, double &chromare, double &lumare, double &sobelref); void copy_ref (int call, int sp, LabImage* spotbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, int sk, const struct local_params & lp, double &huerefspot, double &chromarefspot, double &lumarefspot); void paste_ref (int call, int sp, LabImage* spotbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, int sk, const struct local_params & lp, double &huerefspot, double &chromarefspot, double &lumarefspot); - void Lab_Local (LocallabParams &loc, int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, double &hueref, double &chromaref, double &lumaref); + void Lab_Local (LocallabParams &loc, int call, int sp, float** shbuffer, LabImage* original, LabImage* transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, double &hueref, double &chromaref, double &lumaref, double &sobelref); void addGaNoise (LabImage *lab, LabImage *dst, const float mean, const float variance, const int sk); void BlurNoise_Localold (int call, const struct local_params& lp, LabImage* original, LabImage* transformed, const LabImage* const tmp1, int cx, int cy); void InverseBlurNoise_Local (const struct local_params& lp, LabImage* original, LabImage* transformed, const LabImage* const tmp1, int cx, int cy); diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index 32bd7588e..2e98f9be1 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -161,8 +161,20 @@ struct local_params { }; -static void SobelLuma (float ** sobelL, float **deltasobelL, float **luma, int bfw, int bfh) +static void SobelCannyLuma (LabImage *sobelL, LabImage *deltasobelL, LabImage *luma, int bfw, int bfh) { + //base of the process to detect shape in complement of deltaE + //use for calcualte Spot reference + // and for structure of the shape + // actually , as thr program don't use these function, I just create a simple "Canny" near of Sobel. This can be completed after with teta, etc. + float *tmLBuffer = new float[bfh * bfw]; + float *tmL[bfh]; + + for (int i = 0; i < bfh; i++) { + tmL[i] = &tmLBuffer[i * bfw]; + } + + int GX[3][3]; int GY[3][3]; float SUML; @@ -191,38 +203,58 @@ static void SobelLuma (float ** sobelL, float **deltasobelL, float **luma, int b GY[2][1] = -2; GY[2][2] = -1; //inspired from Chen Guanghua Zhang Xiaolong - // edge detection to improve auto WB - // if (edg) { + //Gaussian 1.4 to blur and denoise + for (int i = 2; i < bfh - 2; i++) { + for (int j = 2; j < bfw - 2; j++) { + //Gaussian 1.4 + // 2 4 5 4 2 + // 4 9 12 9 4 + // 5 12 15 12 5 + // 4 9 12 9 4 + // 2 4 5 4 2 + // divi 159 + tmL[i][j] = (15.f * luma->L[i][j] + 12.f * luma->L[i - 1][j] + 12.f * luma->L[i + 1][j] + + 12.f * luma->L[i][j + 1] + 12.f * luma->L[i][j - 1] + 9.f * luma->L[i - 1][j - 1] + + 9.f * luma->L[i - 1][j + 1] + 9.f * luma->L[i + 1][j - 1] + 9.f * luma->L[i + 1][j + 1] + + 5.f * luma->L[i - 2][j] + 5.f * luma->L[i + 2][j] + 5.f * luma->L[i][j - 2] + 5.f * luma->L[i][j + 2] + + 4.f * luma->L[i - 2][j - 1] + 4.f * luma->L[i - 2][j + 1] + 4.f * luma->L[i + 2][j + 1] + 4.f * luma->L[i + 2][j - 1] + + 4.f * luma->L[i - 1][j - 2] + 4.f * luma->L[i - 1][j + 2] + 4.f * luma->L[i + 1][j + 2] + 4.f * luma->L[i + 1][j - 2] + + 2.f * luma->L[i - 2][j - 2] + 2.f * luma->L[i - 2][j + 2] + 2.f * luma->L[i + 2][j - 2] + 2.f * luma->L[i + 2][j + 2] + ) * 0.0062893f; + + } + } + + { for (int y = 0; y < bfh ; y++) { for (int x = 0; x < bfw ; x++) { - sobelL[y][x] = 0.f; - deltasobelL[y][x] = 0.f; + sobelL->L[y][x] = 0.f; + deltasobelL->L[y][x] = 0.f; } } - for (int y = 0; y < bfh ; y++) { - for (int x = 0; x < bfw ; x++) { + for (int y = 2; y < bfh - 2 ; y++) { + for (int x = 2; x < bfw - 2 ; x++) { sumXL = 0.f; sumYL = 0.f; - /*Image Boundaries*/ - if (y == 0 || y == bfh - 1) { + if (y == 2 || y == bfh - 3) { SUML = 0.f; - } else if (x == 0 || x == bfw - 1) { + } else if (x == 2 || x == bfw - 3) { SUML = 0.f; } else { for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { - sumXL += GX[j + 1][i + 1] * luma[y + i][x + j]; + sumXL += GX[j + 1][i + 1] * tmL[y + i][x + j]; } } for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { - sumYL += GY[j + 1][i + 1] * luma[y + i][x + j]; + sumYL += GY[j + 1][i + 1] * tmL[y + i][x + j]; } } @@ -233,12 +265,15 @@ static void SobelLuma (float ** sobelL, float **deltasobelL, float **luma, int b SUML = CLIPLOC (SUML); - sobelL[y][x] = SUML; - deltasobelL[y][x] = SUML - luma[y][x]; + sobelL->L[y][x] = SUML; + deltasobelL->L[y][x] = SUML - tmL[y][x]; } } } + + delete [] tmLBuffer; + } @@ -5274,7 +5309,7 @@ void ImProcFunctions::InverseColorLight_Local (const struct local_params & lp, L } } -void ImProcFunctions::calc_ref (int call, int sp, float** shbuffer, LabImage * original, LabImage * transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, LUTf & cclocalcurve, LUTf & sklocalcurve, double & hueref, double & chromaref, double & lumaref) +void ImProcFunctions::calc_ref (int call, int sp, float** shbuffer, LabImage * original, LabImage * transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, LUTf & cclocalcurve, LUTf & sklocalcurve, double & hueref, double & chromaref, double & lumaref, double &sobelref) { if (params->locallab.enabled) { //always calculate hueref, chromaref, lumaref before others operations use in normal mode for all modules exceprt denoise @@ -5286,29 +5321,80 @@ void ImProcFunctions::calc_ref (int call, int sp, float** shbuffer, LabImage * o double aveB = 0.; double aveL = 0.; double aveChro = 0.; + double avesobel = 0.; // int precision for the counters int nab = 0; + int nso = 0; // single precision for the result float avA, avB, avL; int spotSize = 0.88623f * max (1, lp.cir / sk); //18 //O.88623 = sqrt(PI / 4) ==> sqare equal to circle + int spotSise2; // = 0.88623f * max (1, lp.cir / sk); //18 // very small region, don't use omp here // printf("cy=%i cx=%i yc=%f xc=%f circ=%i spot=%i tH=%i tW=%i sk=%i\n", cy, cx, lp.yc, lp.xc, lp.cir, spotSize, transformed->H, transformed->W, sk); // printf("ymin=%i ymax=%i\n", max (cy, (int) (lp.yc - spotSize)),min (transformed->H + cy, (int) (lp.yc + spotSize + 1)) ); // printf("xmin=%i xmax=%i\n", max (cx, (int) (lp.xc - spotSize)),min (transformed->W + cx, (int) (lp.xc + spotSize + 1)) ); + LabImage *sobelL; + LabImage *deltasobelL; + LabImage *origsob; + int spotSi = 1 + 2 * max (1, lp.cir / sk); + if (spotSi < 5) { + spotSi = 5; + } + + spotSise2 = (spotSi - 1) / 2; + origsob = new LabImage (spotSi, spotSi); + sobelL = new LabImage (spotSi, spotSi); + deltasobelL = new LabImage (spotSi, spotSi); + + //ref for luma, chroma, hue for (int y = max (cy, (int) (lp.yc - spotSize)); y < min (transformed->H + cy, (int) (lp.yc + spotSize + 1)); y++) { for (int x = max (cx, (int) (lp.xc - spotSize)); x < min (transformed->W + cx, (int) (lp.xc + spotSize + 1)); x++) { aveL += original->L[y - cy][x - cx]; aveA += original->a[y - cy][x - cx]; aveB += original->b[y - cy][x - cx]; aveChro += sqrtf (SQR (original->b[y - cy][x - cx]) + SQR (original->a[y - cy][x - cx])); - nab++; } } + //ref for sobel + bool toto = false; + + if (toto) { + for (int y = max (cy, (int) (lp.yc - spotSise2)); y < min (transformed->H + cy, (int) (lp.yc + spotSise2 + 1)); y++) { + for (int x = max (cx, (int) (lp.xc - spotSise2)); x < min (transformed->W + cx, (int) (lp.xc + spotSise2 + 1)); x++) { + int yb = max (cy, (int) (lp.yc - spotSise2)); + + int xb = max (cx, (int) (lp.xc - spotSise2)); + + int z = y - yb; + int u = x - xb; + origsob->L[z][u] = original->L[y - cy][x - cx]; + nso++; + } + } + + + SobelCannyLuma (sobelL, deltasobelL, origsob, spotSi, spotSi ); + int nbs = 0; + + for (int y = 0; y < spotSi ; y ++) + for (int x = 0; x < spotSi ; x ++) { + avesobel += deltasobelL->L[y][x]; + nbs++; + } + + sobelref = avesobel / nbs; + // printf ("sobelref=%f \n", sobelref); + } + + delete sobelL; + + delete deltasobelL; + delete origsob; aveL = aveL / nab; aveA = aveA / nab; aveB = aveB / nab; @@ -5416,7 +5502,7 @@ void ImProcFunctions::paste_ref (int call, int sp, LabImage * spotbuffer, LabIma void ImProcFunctions::Lab_Local (LocallabParams &loc, int call, int sp, float** shbuffer, LabImage * original, LabImage * transformed, int sx, int sy, int cx, int cy, int oW, int oH, int fw, int fh, bool locutili, int sk, const LocretigainCurve & locRETgainCcurve, bool locallutili, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, - bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurveloc, LUTf & shtonecurveloc, LUTf & tonecurveloc, double & hueref, double & chromaref, double & lumaref) + bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurveloc, LUTf & shtonecurveloc, LUTf & tonecurveloc, double & hueref, double & chromaref, double & lumaref, double & sobelref) { //general call of others functions : important return hueref, chromaref, lumaref if (params->locallab.enabled) { diff --git a/rtengine/procevents.h b/rtengine/procevents.h index 6d401a28b..bdf58f3f2 100644 --- a/rtengine/procevents.h +++ b/rtengine/procevents.h @@ -609,6 +609,7 @@ enum ProcEvent { EvlocallabblurMethod = 579, EvlocallabdustMethod = 580, Evlocallablastdust = 581, + Evlocallabsobelref = 582, NUMOFEVENTS diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index f6a1aecb5..7d5f37183 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1053,6 +1053,7 @@ void LocallabParams::setDefaults() hueref = 1.; chromaref = 50.; lumaref = 50.; + sobelref = 0.; str = 0; neigh = 50; vart = 200; @@ -3240,6 +3241,7 @@ int ProcParams::save (const Glib::ustring &fname, const Glib::ustring &fname2, b keyFile.set_double ("Locallab", "Hueref", locallab.hueref); } + if (!pedited || pedited->locallab.chromaref) { keyFile.set_double ("Locallab", "Chromaref", locallab.chromaref); } @@ -3248,6 +3250,10 @@ int ProcParams::save (const Glib::ustring &fname, const Glib::ustring &fname2, b keyFile.set_double ("Locallab", "Lumaref", locallab.lumaref); } + if (!pedited || pedited->locallab.sobelref) { + keyFile.set_double ("Locallab", "Sobelref", locallab.sobelref); + } + if (!pedited || pedited->locallab.vart) { keyFile.set_integer ("Locallab", "Vart", locallab.vart); } @@ -5257,6 +5263,14 @@ int ProcParams::load (const Glib::ustring &fname, ParamsEdited* pedited) } } + if (keyFile.has_key ("Locallab", "Sobelref")) { + locallab.sobelref = keyFile.get_double ("Locallab", "Sobelref"); + + if (pedited) { + pedited->locallab.sobelref = true; + } + } + if (keyFile.has_key ("Locallab", "Vart")) { locallab.vart = keyFile.get_integer ("Locallab", "Vart"); @@ -10073,6 +10087,7 @@ bool ProcParams::operator== (const ProcParams& other) && locallab.hueref == other.locallab.hueref && locallab.chromaref == other.locallab.chromaref && locallab.lumaref == other.locallab.lumaref + && locallab.sobelref == other.locallab.sobelref && locallab.vart == other.locallab.vart && locallab.threshold == other.locallab.threshold && locallab.chromacbdl == other.locallab.chromacbdl diff --git a/rtengine/procparams.h b/rtengine/procparams.h index e2c8556de..c42fe7f0a 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -1011,6 +1011,7 @@ public: double hueref; double chromaref; double lumaref; + double sobelref; int str; int neigh; int nbspot; diff --git a/rtengine/refreshmap.cc b/rtengine/refreshmap.cc index 2df3d53b3..18137687b 100644 --- a/rtengine/refreshmap.cc +++ b/rtengine/refreshmap.cc @@ -608,7 +608,8 @@ int refreshmap[rtengine::NUMOFEVENTS] = { LUMINANCECURVE, //Evlocallabchromacbdl LUMINANCECURVE, //EvlocallabblurMethod LUMINANCECURVE, //EvlocallabdustMethod - LUMINANCECURVE //Evlocallablastdust + LUMINANCECURVE, //Evlocallablastdust + LUMINANCECURVE // Evlocallabsobelref }; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 167209af7..c043d6d8c 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -1102,7 +1102,7 @@ private: } ifstream fich (datalab, ios::in); - int maxdata = 81;//78;//73 10011 + int maxdata = 82;//78;//73 10011 if (fich && versionmip != 0) { std::string inser; @@ -1327,9 +1327,10 @@ private: dataspots[77][0] = 2; } - dataspots[maxdata - 3][0] = 100.f * params.locallab.hueref; - dataspots[maxdata - 2][0] = params.locallab.chromaref; - dataspots[maxdata - 1][0] = params.locallab.lumaref; + dataspots[maxdata - 4][0] = 100.f * params.locallab.hueref; + dataspots[maxdata - 3][0] = params.locallab.chromaref; + dataspots[maxdata - 2][0] = params.locallab.lumaref; + dataspots[maxdata - 1][0] = params.locallab.sobelref; //curve Reti local int siz = params.locallab.localTgaincurve.size(); @@ -1595,6 +1596,7 @@ private: params.locallab.hueref = INFINITY; params.locallab.chromaref = INFINITY; params.locallab.lumaref = INFINITY; + params.locallab.sobelref = INFINITY; params.locallab.circrad = dataspots[2][sp]; params.locallab.locX = dataspots[3][sp]; @@ -1783,9 +1785,10 @@ private: params.locallab.dustMethod = "pas" ; } - params.locallab.hueref = ((float) dataspots[maxdata - 3][sp]) / 100.f; - params.locallab.chromaref = dataspots[maxdata - 2][sp]; - params.locallab.lumaref = dataspots[maxdata - 1][sp]; + params.locallab.hueref = ((float) dataspots[maxdata - 4][sp]) / 100.f; + params.locallab.chromaref = dataspots[maxdata - 3][sp]; + params.locallab.lumaref = dataspots[maxdata - 2][sp]; + params.locallab.sobelref = dataspots[maxdata - 1][sp]; int *s_datc; @@ -1963,14 +1966,16 @@ private: 1); double huere, chromare, lumare; + double sobelre; - ipf.calc_ref (2, sp, (float**)shbuffer, labView, labView, 0, 0, 0, 0, fw, fh, fw, fh, locutili, 1, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, cclocalcurve, sklocalcurve, huere, chromare, lumare); + ipf.calc_ref (2, sp, (float**)shbuffer, labView, labView, 0, 0, 0, 0, fw, fh, fw, fh, locutili, 1, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, cclocalcurve, sklocalcurve, huere, chromare, lumare, sobelre); params.locallab.hueref = huere; params.locallab.chromaref = chromare; params.locallab.lumaref = lumare; + params.locallab.sobelref = sobelre; ipf.Lab_Local (params.locallab, 2, sp, (float**)shbuffer, labView, labView, 0, 0, 0, 0, fw, fh, fw, fh, locutili, 1, locRETgainCurve, locallutili, lllocalcurve, loclhCurve, lochhCurve, - LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref); + LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, params.locallab.hueref, params.locallab.chromaref, params.locallab.lumaref, params.locallab.sobelref); lllocalcurve.clear(); cclocalcurve.clear(); sklocalcurve.clear(); diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index 75ed00b6b..0db1d3172 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -108,6 +108,7 @@ Locallab::Locallab (): hueref (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_HUEREF"), -3.15, 3.15, 0.01, 0))), chromaref (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_CHROMAREF"), 0, 200, 0.01, 0))), lumaref (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_LUMAMAREF"), 0, 100, 0.01, 0))), + sobelref (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_SOBELREF"), 0, 100, 0.01, 0))), centerXbuf (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_CENTERBUF_X"), -1000, 1000, 1, 0))), centerYbuf (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_CENTERBUF_Y"), -1000, 1000, 1, 0))), adjblur (Gtk::manage (new Adjuster (M ("TP_LOCALLAB_ADJBLUR"), 0, 100, 1, 0))), @@ -484,15 +485,18 @@ Locallab::Locallab (): hueref->setAdjusterListener (this); chromaref->setAdjusterListener (this); lumaref->setAdjusterListener (this); + sobelref->setAdjusterListener (this); pack_start (*hueref); pack_start (*chromaref); pack_start (*lumaref); + pack_start (*sobelref); anbspot->hide();//keep anbspot - i used it to test diffrent algo... hueref->hide(); chromaref->hide(); lumaref->hide(); + sobelref->hide(); ctboxS->pack_start (*Smethod); shapeBox->pack_start (*ctboxS); @@ -653,7 +657,7 @@ Locallab::Locallab (): dustBox->pack_start (*centerYbuf); dustBox->pack_start (*adjblur); dustFrame->add (*dustBox); - // colorBox->pack_start (*dustFrame); +// colorBox->pack_start (*dustFrame); centerXbuf->hide(); centerYbuf->hide(); @@ -1751,10 +1755,11 @@ bool Locallab::localComputed_ () dustMethod->set_active (2); } - double intermed = 0.01 * (double) nextdatasp[75]; + double intermed = 0.01 * (double) nextdatasp[78]; hueref->setValue (intermed); - chromaref->setValue (nextdatasp[76]); - lumaref->setValue (nextdatasp[77]); + chromaref->setValue (nextdatasp[79]); + lumaref->setValue (nextdatasp[80]); + sobelref->setValue (nextdatasp[81]); int *s_datc; s_datc = new int[70]; @@ -2034,7 +2039,7 @@ bool Locallab::localComputed_ () void Locallab::localChanged (int **datasp, std::string datastr, std::string ll_str, std::string lh_str, std::string cc_str, std::string hh_str, std::string sk_str, std::string ps_str, std::string ex_str, int sp, int maxdat) { - for (int i = 2; i < 81; i++) { + for (int i = 2; i < 82; i++) { nextdatasp[i] = datasp[i][sp]; } @@ -2073,6 +2078,7 @@ void Locallab::read (const ProcParams* pp, const ParamsEdited* pedited) hueref->hide(); chromaref->hide(); lumaref->hide(); + sobelref->hide(); centerXbuf->hide(); centerYbuf->hide(); @@ -2156,6 +2162,7 @@ void Locallab::read (const ProcParams* pp, const ParamsEdited* pedited) hueref->setEditedState (pedited->locallab.hueref ? Edited : UnEdited); chromaref->setEditedState (pedited->locallab.chromaref ? Edited : UnEdited); lumaref->setEditedState (pedited->locallab.lumaref ? Edited : UnEdited); + sobelref->setEditedState (pedited->locallab.sobelref ? Edited : UnEdited); transit->setEditedState (pedited->locallab.transit ? Edited : UnEdited); str->setEditedState (pedited->locallab.str ? Edited : UnEdited); neigh->setEditedState (pedited->locallab.neigh ? Edited : UnEdited); @@ -2302,6 +2309,7 @@ void Locallab::read (const ProcParams* pp, const ParamsEdited* pedited) hueref->setValue (pp->locallab.hueref); chromaref->setValue (pp->locallab.chromaref); lumaref->setValue (pp->locallab.lumaref); + sobelref->setValue (pp->locallab.sobelref); vart->setValue (pp->locallab.vart); chrrt->setValue (pp->locallab.chrrt); cTgainshape->setCurve (pp->locallab.localTgaincurve); @@ -2461,6 +2469,7 @@ void Locallab::read (const ProcParams* pp, const ParamsEdited* pedited) hueref->hide(); chromaref->hide(); lumaref->hide(); + sobelref->hide(); centerXbuf->hide(); centerYbuf->hide(); @@ -2769,6 +2778,7 @@ void Locallab::write (ProcParams* pp, ParamsEdited* pedited) pp->locallab.hueref = hueref->getValue (); pp->locallab.chromaref = chromaref->getValue (); pp->locallab.lumaref = lumaref->getValue (); + pp->locallab.sobelref = sobelref->getValue (); pp->locallab.vart = vart->getIntValue (); pp->locallab.chrrt = chrrt->getIntValue (); pp->locallab.localTgaincurve = cTgainshape->getCurve (); @@ -2875,6 +2885,7 @@ void Locallab::write (ProcParams* pp, ParamsEdited* pedited) pedited->locallab.hueref = hueref->getEditedState (); pedited->locallab.chromaref = chromaref->getEditedState (); pedited->locallab.lumaref = lumaref->getEditedState (); + pedited->locallab.sobelref = sobelref->getEditedState (); pedited->locallab.vart = vart->getEditedState (); pedited->locallab.chrrt = chrrt->getEditedState (); @@ -3607,6 +3618,7 @@ void Locallab::setDefaults (const ProcParams * defParams, const ParamsEdited * p hueref->setDefault (defParams->locallab.hueref); chromaref->setDefault (defParams->locallab.chromaref); lumaref->setDefault (defParams->locallab.lumaref); + sobelref->setDefault (defParams->locallab.sobelref); vart->setDefault (defParams->locallab.vart); chrrt->setDefault (defParams->locallab.chrrt); @@ -3677,6 +3689,7 @@ void Locallab::setDefaults (const ProcParams * defParams, const ParamsEdited * p hueref->setDefaultEditedState (pedited->locallab.hueref ? Edited : UnEdited); chromaref->setDefaultEditedState (pedited->locallab.chromaref ? Edited : UnEdited); lumaref->setDefaultEditedState (pedited->locallab.lumaref ? Edited : UnEdited); + sobelref->setDefaultEditedState (pedited->locallab.sobelref ? Edited : UnEdited); vart->setDefaultEditedState (pedited->locallab.vart ? Edited : UnEdited); chrrt->setDefaultEditedState (pedited->locallab.chrrt ? Edited : UnEdited); @@ -3746,6 +3759,7 @@ void Locallab::setDefaults (const ProcParams * defParams, const ParamsEdited * p hueref->setDefaultEditedState (Irrelevant); chromaref->setDefaultEditedState (Irrelevant); lumaref->setDefaultEditedState (Irrelevant); + sobelref->setDefaultEditedState (Irrelevant); vart->setDefaultEditedState (Irrelevant); chrrt->setDefaultEditedState (Irrelevant); @@ -3780,6 +3794,7 @@ void Locallab::adjusterChanged (Adjuster * a, double newval) hueref->hide(); chromaref->hide(); lumaref->hide(); + sobelref->hide(); centerXbuf->hide(); centerYbuf->hide(); @@ -3936,6 +3951,8 @@ void Locallab::adjusterChanged (Adjuster * a, double newval) listener->panelChanged (Evlocallabchromaref, "");//anbspot->getTextValue()); } else if (a == lumaref) { listener->panelChanged (Evlocallablumaref, "");//anbspot->getTextValue()); + } else if (a == sobelref) { + listener->panelChanged (Evlocallabsobelref, "");//anbspot->getTextValue()); } else if (a == vart) { listener->panelChanged (Evlocallabvart, vart->getTextValue()); } else if (a == chrrt) { @@ -3980,6 +3997,7 @@ void Locallab::enabledChanged () hueref->hide(); chromaref->hide(); lumaref->hide(); + sobelref->hide(); if (listener) { if (get_inconsistent()) { @@ -4091,6 +4109,7 @@ void Locallab::trimValues (rtengine::procparams::ProcParams * pp) hueref->trimValue (pp->locallab.hueref); chromaref->trimValue (pp->locallab.chromaref); lumaref->trimValue (pp->locallab.lumaref); + sobelref->trimValue (pp->locallab.sobelref); vart->trimValue (pp->locallab.vart); chrrt->trimValue (pp->locallab.chrrt); @@ -4116,6 +4135,7 @@ void Locallab::setBatchMode (bool batchMode) hueref->hide (); chromaref->hide (); lumaref->hide (); + sobelref->hide (); degree->showEditedCB (); locY->showEditedCB (); @@ -4171,6 +4191,7 @@ void Locallab::setBatchMode (bool batchMode) hueref->showEditedCB (); chromaref->showEditedCB (); lumaref->showEditedCB (); + sobelref->showEditedCB (); vart->showEditedCB (); LocalcurveEditorgainT->setBatchMode (batchMode); LocalcurveEditorgainTrab->setBatchMode (batchMode); diff --git a/rtgui/locallab.h b/rtgui/locallab.h index 5e372da75..03a292e51 100644 --- a/rtgui/locallab.h +++ b/rtgui/locallab.h @@ -117,6 +117,7 @@ private: Adjuster* const hueref; Adjuster* const chromaref; Adjuster* const lumaref; + Adjuster* const sobelref; Adjuster* const centerXbuf; Adjuster* const centerYbuf; Adjuster* const adjblur; @@ -220,7 +221,7 @@ private: - int nextdatasp[81]; + int nextdatasp[82]; int nextlength; std::string nextstr; std::string nextstr2; diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 43de8aab8..68dbc94a8 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -384,6 +384,7 @@ void ParamsEdited::set (bool v) locallab.hueref = v; locallab.chromaref = v; locallab.lumaref = v; + locallab.sobelref = v; locallab.vart = v; locallab.localTgaincurve = v; locallab.localTgaincurverab = v; @@ -1019,6 +1020,7 @@ void ParamsEdited::initFrom (const std::vector locallab.hueref = locallab.hueref && p.locallab.hueref == other.locallab.hueref; locallab.chromaref = locallab.chromaref && p.locallab.chromaref == other.locallab.chromaref; locallab.lumaref = locallab.lumaref && p.locallab.lumaref == other.locallab.lumaref; + locallab.sobelref = locallab.sobelref && p.locallab.sobelref == other.locallab.sobelref; locallab.vart = locallab.vart && p.locallab.vart == other.locallab.vart; locallab.localTgaincurve = locallab.localTgaincurve && p.locallab.localTgaincurve == other.locallab.localTgaincurve; locallab.localTgaincurverab = locallab.localTgaincurverab && p.locallab.localTgaincurverab == other.locallab.localTgaincurverab; @@ -2680,6 +2682,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten toEdit.locallab.lumaref = mods.locallab.lumaref; } + if (locallab.sobelref) { + toEdit.locallab.sobelref = mods.locallab.sobelref; + } + if (locallab.vart) { toEdit.locallab.vart = mods.locallab.vart; } diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index 8fe0b84ef..b0f3cda6a 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -488,6 +488,7 @@ public: bool hueref; bool chromaref; bool lumaref; + bool sobelref; bool vart; bool activlum; bool invers;