diff --git a/rtengine/iplocalcontrast.cc b/rtengine/iplocalcontrast.cc index 9a19536b2..cdf463130 100644 --- a/rtengine/iplocalcontrast.cc +++ b/rtengine/iplocalcontrast.cc @@ -33,6 +33,8 @@ namespace rtengine { + extern const Settings* settings; + LocallabParams locallab; ///< Local lab parameters void ImProcFunctions::localContrast(LabImage *lab, float **destination, const LocalContrastParams &localContrastParams, bool fftwlc, double scale) @@ -59,11 +61,15 @@ void ImProcFunctions::localContrast(LabImage *lab, float **destination, const Lo //emprical adjustement between FFTW radius and Gaussainblur //under 50 ==> 10.f //above 400 ==> 1.f - float ak = -9.f / 350.f; - float bk = 10.f - 50.f * ak; - kr = ak * sigma + bk; - if(sigma < 50.f) kr = 10.f; - if(sigma > 400.f) kr = 1.f; + if(settings->fftwsigma == false) {//empirical formula + float ak = -9.f / 350.f; + float bk = 10.f - 50.f * ak; + kr = ak * sigma + bk; + if(sigma < 50.f) kr = 10.f; + if(sigma > 400.f) kr = 1.f; + } else {//sigma *= sigma + kr = sigma; + } // printf("kr=%f \n", kr); ImProcFunctions::fftw_convol_blur2(lab->L, buf, width, height, kr * sigma, 0, 0); } diff --git a/rtengine/iplocallab.cc b/rtengine/iplocallab.cc index e236335e0..ffc2c3cae 100644 --- a/rtengine/iplocallab.cc +++ b/rtengine/iplocallab.cc @@ -4010,7 +4010,8 @@ void ImProcFunctions::fftw_convol_blur(float *input, float *output, int bfw, int ** n_x n_y relative width and high for kernel ** Gaussian blur is given by G(x,y) = (1/2*PI*sigma) * exp(-(x2 + y2) / 2* sigma2) ** its traduction in Fourier transform is G(x,y) = exp((-sigma)*(PI * x2 + PI * y2)), for some authors it is not sigma but sigma^2..I have tried...huge diffrences with Gaussianblur - ** after several test the only result that works very well is with fftkern = 0 and algo = 0, and as there is big differences with Gaussianblur, I put an empirical correction in Ipretinex and Iplocalcontrast + ** after several test the only result that works very well is with fftkern = 0 and algo = 0, and as there is differences with Gaussianblur, I put an empirical correction in Ipretinex and Iplocalcontrast + ** you can enabled or disabled this function with rtsettings.fftwsigma in options. By defaut empirical formula is disabled ** in fact no importance....if it is this function (for sigma) or another... we are not in research :) */ BENCHFUN @@ -4100,7 +4101,7 @@ void ImProcFunctions::fftw_convol_blur(float *input, float *output, int bfw, int for(int j = 0; j < bfh; j++){ int index = j * bfw; for(int i = 0; i < bfw; i++) - out[i + index] *= exp((float)(-radius)*(n_x * i * i + n_y * j * j));//apply Gauss kernel whithout FFT - some authors says radius*radius but huge differences with Gaussianblur + out[i + index] *= exp((float)(-radius)*(n_x * i * i + n_y * j * j));//apply Gauss kernel whithout FFT - some authors says radius*radius but differences with Gaussianblur } } else if(algo == 1) { #ifdef _OPENMP diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index b75360f32..1878b682d 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -969,26 +969,31 @@ void ImProcFunctions::MSRLocal(int sp, bool fftw, int lum, LabImage * bufreti, L //emprical adjustement between FFTW radius and Gaussainblur //under 50 ==> 10.f // 400 ==> 1.f - float sigm = RetinexScales[scale]; - float ak = -9.f / 350.f; - float bk = 10.f - 50.f * ak; - kr = ak * sigm + bk; - if(sigm < 50.f) kr = 10.f; - //above 400 at 5000 ==> 20.f - if(sigm > 400.f) {//increase ==> 5000 - float ka = 19.f / 4600.f; - float kb = 1.f - 400 * ka; - kr = ka * sigm + kb; - float kga = -0.14f / 4600.f;//decrease - float kgb = 1.f - 400.f * kga; - kg = kga * sigm + kgb; - if(sigm > 5000.f) { - kr = ka * 5000.f + kb; - kg = kga * 5000.f + kgb; - } + float sigm = 1.f; + if(settings->fftwsigma == false) {//empirical formula + sigm = RetinexScales[scale]; + float ak = -9.f / 350.f; + float bk = 10.f - 50.f * ak; + kr = ak * sigm + bk; + if(sigm < 50.f) kr = 10.f; + //above 400 at 5000 ==> 20.f + if(sigm > 400.f) {//increase ==> 5000 + float ka = 19.f / 4600.f; + float kb = 1.f - 400 * ka; + kr = ka * sigm + kb; + float kga = -0.14f / 4600.f;//decrease + float kgb = 1.f - 400.f * kga; + kg = kga * sigm + kgb; + if(sigm > 5000.f) { + kr = ka * 5000.f + kb; + kg = kga * 5000.f + kgb; + } + } + } else {//sigma *= sigma + kg = 1.f; + kr = sigm; } - if(!fftw) { #ifdef _OPENMP #pragma omp parallel //disabled with FFTW diff --git a/rtengine/settings.h b/rtengine/settings.h index eaa8545a9..de0406060 100644 --- a/rtengine/settings.h +++ b/rtengine/settings.h @@ -84,6 +84,7 @@ public: double reduchigh; double reduclow; bool detectshape; + bool fftwsigma; int previewselection; double cbdlsensi; // bool showtooltip; diff --git a/rtgui/options.cc b/rtgui/options.cc index b985e9132..79b7a3fee 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -596,6 +596,7 @@ void Options::setDefaults() rtSettings.detectshape = true;//experimental new detection shape rtSettings.previewselection = 5;//betwen 1 to 40 rtSettings.cbdlsensi = 1.0;//betwen 0.001 to 1 + rtSettings.fftwsigma = true; //choice between sigma^2 or empirical formula // end locallab @@ -760,6 +761,10 @@ void Options::readFromFile(Glib::ustring fname) rtSettings.detectshape = keyFile.get_boolean("General", "Detectshape"); } + if (keyFile.has_key("General", "Fftwsigma")) { + rtSettings.fftwsigma = keyFile.get_boolean("General", "Fftwsigma"); + } + if (keyFile.has_key("General", "Cropsleep")) { rtSettings.cropsleep = keyFile.get_integer("General", "Cropsleep"); } @@ -1988,6 +1993,7 @@ void Options::saveToFile(Glib::ustring fname) keyFile.set_double("General", "Reduchigh", rtSettings.reduchigh); keyFile.set_double("General", "Reduclow", rtSettings.reduclow); keyFile.set_boolean("General", "Detectshape", rtSettings.detectshape); + keyFile.set_boolean("General", "Fftwsigma", rtSettings.fftwsigma); keyFile.set_integer("External Editor", "EditorKind", editorToSendTo); keyFile.set_string("External Editor", "GimpDir", gimpDir);