Improve shape detection with mask - clean code - fixe some bugs

This commit is contained in:
Desmis 2019-01-10 08:56:32 +01:00
parent f0de694c6a
commit e795d902ab
8 changed files with 51 additions and 47 deletions

View File

@ -1697,14 +1697,13 @@ void LocCCmaskCurve::Set(const Curve &pCurve)
void LocCCmaskCurve::Set(const std::vector<double> &curvePoints, bool &HHutili)
void LocCCmaskCurve::Set(const std::vector<double> &curvePoints)
{
// if (HHutili && !curvePoints.empty() && curvePoints[0] > FCT_Linear && curvePoints[0] < FCT_Unchanged) {
if (!curvePoints.empty() && curvePoints[0] > FCT_Linear && curvePoints[0] < FCT_Unchanged) {
FlatCurve ttcurve(curvePoints, false, CURVES_MIN_POLY_POINTS / 2);
ttcurve.setIdentityValue(0.);
Set(ttcurve);
HHutili = true;
} else {
Reset();
}
@ -1743,14 +1742,13 @@ void LocLLmaskCurve::Set(const Curve &pCurve)
void LocLLmaskCurve::Set(const std::vector<double> &curvePoints, bool &HHutili)
void LocLLmaskCurve::Set(const std::vector<double> &curvePoints)
{
// if (HHutili && !curvePoints.empty() && curvePoints[0] > FCT_Linear && curvePoints[0] < FCT_Unchanged) {
if (!curvePoints.empty() && curvePoints[0] > FCT_Linear && curvePoints[0] < FCT_Unchanged) {
FlatCurve ttcurve(curvePoints, false, CURVES_MIN_POLY_POINTS / 2);
ttcurve.setIdentityValue(0.);
Set(ttcurve);
HHutili = true;
} else {
Reset();
}

View File

@ -702,7 +702,7 @@ public:
virtual ~LocCCmaskCurve() {};
LocCCmaskCurve();
void Reset();
void Set(const std::vector<double> &curvePoints, bool &HHutili);
void Set(const std::vector<double> &curvePoints);
float getSum() const
{
return sum;
@ -730,7 +730,7 @@ public:
virtual ~LocLLmaskCurve() {};
LocLLmaskCurve();
void Reset();
void Set(const std::vector<double> &curvePoints, bool &HHutili);
void Set(const std::vector<double> &curvePoints);
float getSum() const
{
return sum;

View File

@ -895,8 +895,6 @@ void Crop::update(int todo)
LUTu lhist16loc2(32770, 0);
bool LHutili = parent->LHutili;
bool HHutili = parent->HHutili;
bool CCmaskutili = parent->CCmaskutili;
bool LLmaskutili = parent->LLmaskutili;
LUTu dummy;
bool needslocal = params.locallab.enabled;
LocretigainCurve locRETgainCurve;
@ -919,8 +917,8 @@ void Crop::update(int todo)
locRETgainCurve.Set(params.locallab.spots.at(sp).localTgaincurve);
loclhCurve.Set(params.locallab.spots.at(sp).LHcurve, LHutili);
lochhCurve.Set(params.locallab.spots.at(sp).HHcurve, HHutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve, CCmaskutili);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve, LLmaskutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve);
locccmasexpCurve.Set(params.locallab.spots.at(sp).CCmaskexpcurve);
locllmasexpCurve.Set(params.locallab.spots.at(sp).LLmaskexpcurve);
locallutili = false;
@ -952,7 +950,7 @@ void Crop::update(int todo)
sca);
parent->ipf.Lab_Local(1, sp, parent->sobelrefs, (float**)shbuffer, labnCrop, labnCrop, reservCrop, cropx / skip, cropy / skip, skips(parent->fw, skip), skips(parent->fh, skip), skip, locRETgainCurve, lllocalcurve2,
loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve, CCmaskutili, LLmaskutili, LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, lightCurveloc2, huerefblu, huere, chromare, lumare, sobelre);
loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve, LHutili, HHutili, cclocalcurve2, localskutili, sklocalcurve2, localexutili, exlocalcurve2, hltonecurveloc2, shtonecurveloc2, tonecurveloc2, lightCurveloc2, huerefblu, huere, chromare, lumare, sobelre);
lllocalcurve2.clear();
cclocalcurve2.clear();

View File

@ -781,14 +781,11 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
localexutili = false;
localcutili = false;
localskutili = false;
CCmaskutili = false;
LLmaskutili = false;
locRETgainCurve.Set(params.locallab.spots.at(sp).localTgaincurve);
loclhCurve.Set(params.locallab.spots.at(sp).LHcurve, LHutili);
lochhCurve.Set(params.locallab.spots.at(sp).HHcurve, HHutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve, CCmaskutili);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve, LLmaskutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve, CCmaskutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve);
locllmasexpCurve.Set(params.locallab.spots.at(sp).LLmaskexpcurve);
locccmasexpCurve.Set(params.locallab.spots.at(sp).CCmaskexpcurve);
CurveFactory::curveLocal(locallutili, params.locallab.spots.at(sp).llcurve, lllocalcurve, sca);
@ -828,7 +825,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
* - maxspot, huerefs, centerx and centery aren't used in Lab_Local (only for printf) so values aren't important
* - shbuffer is used as nullptr
*/
ipf.Lab_Local(3, sp, sobelrefs, (float**)shbuffer, nprevl, nprevl, reserv, 0, 0, pW, pH, scale, locRETgainCurve, lllocalcurve, loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve, CCmaskutili, LLmaskutili,
ipf.Lab_Local(3, sp, sobelrefs, (float**)shbuffer, nprevl, nprevl, reserv, 0, 0, pW, pH, scale, locRETgainCurve, lllocalcurve, loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve,
LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, huerblu, huer, chromar, lumar, sobeler);
if (params.locallab.spots.at(sp).spotMethod == "exc") {

View File

@ -245,8 +245,6 @@ protected:
bool localexutili;
bool LHutili;
bool HHutili;
bool CCmaskutili;
bool LLmaskutili;
LUTf huerefs;
LUTf huerefblurs;
LUTf chromarefs;

View File

@ -289,7 +289,7 @@ public:
void calc_ref(int sp, LabImage* original, LabImage* transformed, int cx, int cy, int oW, int oH, int sk, double &huerefblur, double &huere, double &chromare, double &lumare, double &sobelref, LUTu & histogram);
void copy_ref(LabImage* spotbuffer, LabImage* original, LabImage* transformed, int cx, int cy, int sk, const struct local_params & lp, double &huerefspot, double &chromarefspot, double &lumarefspot);
void paste_ref(LabImage* spotbuffer, LabImage* transformed, int cx, int cy, int sk, const struct local_params & lp);
void Lab_Local(int call, int sp, LUTf & sobelrefs, float** shbuffer, LabImage* original, LabImage* transformed, LabImage* reserved, int cx, int cy, int oW, int oH, int sk, const LocretigainCurve & locRETgainCcurve, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, const LocCCmaskCurve & locccmasCurve, const LocLLmaskCurve & locllmasCurve, const LocCCmaskexpCurve & locccmasexpCurve, const LocLLmaskexpCurve & locllmasexpCurve,bool CCmaskutili, bool LLmaskutili, bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, LUTf & lightCurveloc, double & huerefblur, double &hueref, double &chromaref, double &lumaref, double &sobelref);
void Lab_Local(int call, int sp, LUTf & sobelrefs, float** shbuffer, LabImage* original, LabImage* transformed, LabImage* reserved, int cx, int cy, int oW, int oH, int sk, const LocretigainCurve & locRETgainCcurve, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, const LocCCmaskCurve & locccmasCurve, const LocLLmaskCurve & locllmasCurve, const LocCCmaskexpCurve & locccmasexpCurve, const LocLLmaskexpCurve & locllmasexpCurve, bool &LHutili, bool &HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurve, LUTf & shtonecurve, LUTf & tonecurve, LUTf & lightCurveloc, double & huerefblur, 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);

View File

@ -412,12 +412,7 @@ static void calcLocalParams(int sp, int oW, int oH, const LocallabParams& locall
} else if (locallab.spots.at(sp).showmaskexpMethod == "showmask") {
lp.showmaskexpmet = 4;
}
if (locallab.spots.at(sp).showmaskexpMethod == "none") {
lp.showmaskexpmet = 0;
} else if (locallab.spots.at(sp).showmaskexpMethod == "expo") {
lp.showmaskexpmet = 1;
}
if (locallab.spots.at(sp).blurMethod == "norm") {
lp.blurmet = 0;
@ -5114,18 +5109,19 @@ void ImProcFunctions::Expo_vibr_Local(float moddE, float powdE, int senstype, La
LabImage *origblurmask = nullptr;
float radius = 3.f / sk;
if (lp.showmaskexpmet >= 2 && senstype == 1) {
bool usemask = lp.showmaskexpmet >= 2 && senstype == 1;
if (usemask) {
origblurmask = new LabImage(GW, GH);
#ifdef _OPENMP
#pragma omp parallel
#endif
{
gaussianBlur(originalmask->L, origblurmask->L, GW, GH, radius);
gaussianBlur(originalmask->a, origblurmask->a, GW, GH, radius);
gaussianBlur(originalmask->b, origblurmask->b, GW, GH, radius);
}
}
{
gaussianBlur(originalmask->L, origblurmask->L, GW, GH, radius);
gaussianBlur(originalmask->a, origblurmask->a, GW, GH, radius);
gaussianBlur(originalmask->b, origblurmask->b, GW, GH, radius);
}
}
#ifdef _OPENMP
#pragma omp parallel
#endif
@ -5210,12 +5206,20 @@ void ImProcFunctions::Expo_vibr_Local(float moddE, float powdE, int senstype, La
float rchro = sqrt(SQR(origblur->b[y][x]) + SQR(origblur->a[y][x])) / 327.68f;
#endif
float rL = origblur->L[y][x] / 327.68f;
float rhuemask = 0.f;
float rchromask = 0.f;
float rLmask = 0.f;
float dE = 0.f;
if (lp.showmaskexpmet >= 2 && senstype == 1) {
if (usemask) {
rhuemask = xatan2f(origblurmask->b[y][x], origblurmask->a[y][x]);
rchromask = sqrt(SQR(origblurmask->b[y][x]) + SQR(origblurmask->a[y][x])) / 327.68f;
rLmask = origblurmask->L[y][x] / 327.68f;
dE = sqrt(SQR(refa - origblurmask->a[y][x] / 327.68f) + SQR(refb - origblurmask->b[y][x] / 327.68f) + SQR(lumaref - origblurmask->L[y][x] / 327.68f));
} else {
dE = sqrt(SQR(refa - origblur->a[y][x] / 327.68f) + SQR(refb - origblur->b[y][x] / 327.68f) + SQR(lumaref - rL));
rhuemask = rhue;
rchromask = rchro;
rLmask = rL;
}
float cli = 1.f;
@ -5258,15 +5262,15 @@ void ImProcFunctions::Expo_vibr_Local(float moddE, float powdE, int senstype, La
float realstrb = 1.f;
//prepare shape detection
float deltachro = fabs(rchro - chromaref);
float deltahue = fabs(rhue - hueref);
float deltachro = fabs(rchromask - chromaref);
float deltahue = fabs(rhuemask - hueref);
if (deltahue > rtengine::RT_PI) {
deltahue = - (deltahue - 2.f * rtengine::RT_PI);
}
float deltaE = 20.f * deltahue + deltachro; //between 0 and 280
float deltaL = fabs(lumaref - rL); //between 0 and 100
float deltaL = fabs(lumaref - rLmask); //between 0 and 100
float kch = 1.f;
float kchchro = 1.f;
@ -5836,10 +5840,19 @@ void ImProcFunctions::ColorLight_Local(float moddE, float powdE, int call, LabIm
origblur->b[y][x] = 0.01f;
}
float dE = 0.f;
float rhuemask = 0.f;
float rchromask = 0.f;
float rLmask = 0.f;
if (lp.showmaskcolmet >= 2) {
rhuemask = xatan2f(origblurmask->b[y][x], origblurmask->a[y][x]);
rchromask = sqrt(SQR(origblurmask->b[y][x]) + SQR(origblurmask->a[y][x])) / 327.68f;
rLmask = origblurmask->L[y][x] / 327.68f;
dE = sqrt(SQR(refa - origblurmask->a[y][x] / 327.68f) + SQR(refb - origblurmask->b[y][x] / 327.68f) + SQR(lumaref - origblurmask->L[y][x] / 327.68f));
} else {
dE = sqrt(SQR(refa - origblur->a[y][x] / 327.68f) + SQR(refb - origblur->b[y][x] / 327.68f) + SQR(lumaref - rL));
rhuemask = rhue;
rchromask = rchro;
rLmask = rL;
}
//retriev data curve lightness
float cli = (buflight[loy - begy][lox - begx]);
@ -5888,9 +5901,9 @@ void ImProcFunctions::ColorLight_Local(float moddE, float powdE, int call, LabIm
float realclighsl = 1.f;
float realhh = 0.f;
//evaluate delta Hue and delta Chro
float deltachro = fabs(rchro - chromaref);
float deltachro = fabs(rchromask - chromaref);
float deltahue = fabs(rhue - hueref);
float deltahue = fabs(rhuemask - hueref);
if (deltahue > rtengine::RT_PI) {
deltahue = - (deltahue - 2.f * rtengine::RT_PI);
@ -5898,7 +5911,7 @@ void ImProcFunctions::ColorLight_Local(float moddE, float powdE, int call, LabIm
//pseudo deltaE
float deltaE = 20.f * deltahue + deltachro; //pseudo deltaE between 0 and 280
float deltaL = fabs(lumaref - rL); //between 0 and 100
float deltaL = fabs(lumaref - rLmask); //between 0 and 100
float kchchro = 1.f;
float kch = 1.f;
@ -7565,7 +7578,7 @@ void ImProcFunctions::fftw_denoise(int GW, int GH, int max_numblox_W, int min_nu
void ImProcFunctions::Lab_Local(int call, int sp, LUTf & sobelrefs, float** shbuffer, LabImage * original, LabImage * transformed, LabImage * reserved, int cx, int cy, int oW, int oH, int sk,
const LocretigainCurve & locRETgainCcurve, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, const LocCCmaskCurve & locccmasCurve, const LocLLmaskCurve & locllmasCurve, const LocCCmaskexpCurve & locccmasexpCurve, const LocLLmaskexpCurve & locllmasexpCurve, bool CCmaskutili, bool LLmaskutili,
const LocretigainCurve & locRETgainCcurve, LUTf & lllocalcurve, const LocLHCurve & loclhCurve, const LocHHCurve & lochhCurve, const LocCCmaskCurve & locccmasCurve, const LocLLmaskCurve & locllmasCurve, const LocCCmaskexpCurve & locccmasexpCurve, const LocLLmaskexpCurve & locllmasexpCurve,
bool & LHutili, bool & HHutili, LUTf & cclocalcurve, bool & localskutili, LUTf & sklocalcurve, bool & localexutili, LUTf & exlocalcurve, LUTf & hltonecurveloc, LUTf & shtonecurveloc, LUTf & tonecurveloc, LUTf & lightCurveloc, double & huerefblur, double & hueref, double & chromaref, double & lumaref, double & sobelref)
{
//general call of others functions : important return hueref, chromaref, lumaref

View File

@ -1103,8 +1103,6 @@ private:
// Set local curves of current spot to LUT
bool LHutili = false;
bool HHutili = false;
bool CCmaskutili = false;
bool LLmaskutili = false;
bool locallutili = false;
bool localcutili = false;
bool localskutili = false;
@ -1112,8 +1110,10 @@ private:
locRETgainCurve.Set(params.locallab.spots.at(sp).localTgaincurve);
loclhCurve.Set(params.locallab.spots.at(sp).LHcurve, LHutili);
lochhCurve.Set(params.locallab.spots.at(sp).HHcurve, HHutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve, CCmaskutili);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve, LLmaskutili);
locccmasCurve.Set(params.locallab.spots.at(sp).CCmaskcurve);
locllmasCurve.Set(params.locallab.spots.at(sp).LLmaskcurve);
locccmasexpCurve.Set(params.locallab.spots.at(sp).CCmaskexpcurve);
locllmasexpCurve.Set(params.locallab.spots.at(sp).LLmaskexpcurve);
CurveFactory::curveLocal(locallutili, params.locallab.spots.at(sp).llcurve, lllocalcurve, 1);
CurveFactory::curveCCLocal(localcutili, params.locallab.spots.at(sp).cccurve, cclocalcurve, 1);
CurveFactory::curveskLocal(localskutili, params.locallab.spots.at(sp).skintonescurve, sklocalcurve, 1);
@ -1139,7 +1139,7 @@ private:
hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc,
1);
ipf.Lab_Local(2, sp, sobelrefs, (float**)shbuffer, labView, labView, reservView, 0, 0, fw, fh, 1, locRETgainCurve, lllocalcurve, loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve, CCmaskutili, LLmaskutili,
ipf.Lab_Local(2, sp, sobelrefs, (float**)shbuffer, labView, labView, reservView, 0, 0, fw, fh, 1, locRETgainCurve, lllocalcurve, loclhCurve, lochhCurve, locccmasCurve, locllmasCurve, locccmasexpCurve, locllmasexpCurve,
LHutili, HHutili, cclocalcurve, localskutili, sklocalcurve, localexutili, exlocalcurve, hltonecurveloc, shtonecurveloc, tonecurveloc, lightCurveloc, huerefblu, huere, chromare, lumare, sobelre);
// Clear local curves