From 1f365425588985453f24a4d2556e15d25bd277fa Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 30 Nov 2016 01:17:50 +0100 Subject: [PATCH] pixelshift Diversified green and non green motion detection --- rtengine/pixelshift.cc | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/rtengine/pixelshift.cc b/rtengine/pixelshift.cc index a8fbd7bcb..491ae882b 100644 --- a/rtengine/pixelshift.cc +++ b/rtengine/pixelshift.cc @@ -63,6 +63,34 @@ float colourDiff(float a, float b, bool adaptive, float stddevFactor, float eper } } +float nonGreenDiff(float a, float b, bool adaptive, float stddevFactor, float eperIso, float nreadIso, float prnu, bool showMotion) +{ + // calculate the difference between to green samples + if(adaptive) { + float gDiff = a - b; + gDiff *= eperIso; + gDiff *= gDiff; + float avg = (a + b) / 2.f; + avg *= eperIso; + prnu *= avg; + float stddev = stddevFactor * (avg + nreadIso + prnu * prnu); + float result = gDiff - stddev; + if(!showMotion) { + return result; + } else if(result > 0.f) { // for the motion mask + return std::fabs(a - b) / (std::max(a, b) + 0.01f); + } else { + return 0.f; + } + } else { + float gDiff = std::fabs(a - b); + // add a small epsilon to avoid division by zero + float maxVal = std::max(a, b) + 0.01f; + return gDiff / maxVal; + } +} + + } using namespace std; @@ -269,7 +297,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, bool det float diff2 = ng2 - ng1; if(diff0 * diff2 >= 0.f) { float val = (ng0 + ng2) / 2.f; - float gridMax = colourDiff(ng1, val, true, stddevFactor, eperIsoNonGreen0, nreadIso, prnu, showMotion); + float gridMax = nonGreenDiff(ng1, val, true, stddevFactor, eperIsoNonGreen0, nreadIso, prnu, showMotion); if(gridMax > 0.f) { if(showMotion) { float blend = gridMax * blendFactor; @@ -292,7 +320,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, bool det diff2 = ng2 - ng1; if(diff0 * diff2 >= 0.f) { float val = (ng0 + ng2) / 2.f; - float gridMax = colourDiff(ng1, val, true, stddevFactor, eperIsoNonGreen2, nreadIso, prnu, showMotion); + float gridMax = nonGreenDiff(ng1, val, true, stddevFactor, eperIsoNonGreen2, nreadIso, prnu, showMotion); if(gridMax > 0.f) { if(showMotion) { float blend = gridMax * blendFactor; @@ -317,7 +345,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, bool det float diff2 = ng2 - ng1; if(diff0 * diff2 >= 0.f) { float val = (ng0 + ng2) / 2.f; - float gridMax = colourDiff(ng1, val, true, stddevFactor, eperIsoNonGreen0, nreadIso, prnu, showMotion); + float gridMax = nonGreenDiff(ng1, val, true, stddevFactor, eperIsoNonGreen0, nreadIso, prnu, showMotion); if(gridMax > 0.f) { if(showMotion) { float blend = gridMax * blendFactor; @@ -341,7 +369,7 @@ void RawImageSource::pixelshift(int winx, int winy, int winw, int winh, bool det diff2 = ng2 - ng1; if(diff0 * diff2 >= 0.f) { float val = (ng0 + ng2) / 2.f; - float gridMax = colourDiff(ng1, val, true, stddevFactor, eperIsoNonGreen2, nreadIso, prnu, showMotion); + float gridMax = nonGreenDiff(ng1, val, true, stddevFactor, eperIsoNonGreen2, nreadIso, prnu, showMotion); if(gridMax > 0.f) { if(showMotion) { float blend = gridMax * blendFactor;