accumulation: extend accumulation algorithm to be able to ignore noise lower than a threshold

parent 16f0f2c2
......@@ -48,6 +48,7 @@ namespace lima
{
DEB_CLASS_NAMESPC(DebModControl,"Accumulation::Parameters","Control");
public:
enum Mode {STANDARD,THRESHOLD_BEFORE};
Parameters();
void reset();
......@@ -56,6 +57,8 @@ namespace lima
bool savingFlag; ///< saving flag if true save saturatedImageCounter
std::string savePrefix; ///< prefix filename of saturatedImageCounter (default is saturated_image_counter)
Mode mode;
long long thresholdB4Acc; ///< value used in mode THRESHOLD_BEFORE
};
class ThresholdCallback
......@@ -94,6 +97,12 @@ namespace lima
void setSavePrefix(const std::string &savePrefix);
void getSavePrefix(std::string &savePrefix) const;
void getMode(Parameters::Mode& mode) const;
void setMode(Parameters::Mode mode);
void getThresholdBeforeAcc(long long&) const;
void setThresholdBeforeAcc(const long long&);
// --- variable and data result of Concatenation or Accumulation
void readSaturatedImageCounter(Data&,long frameNumber = -1);
......@@ -159,6 +168,7 @@ namespace lima
void getFrame(Data &,int frameNumber);
void _accFrame(Data &src,Data &dst);
void _accFrameWithThreshold(Data &src,Data &dst,long long threshold_value);
void _calcSaturatedImageNCounters(Data &src,Data &dst);
inline void _callIfNeedThresholdCallback(Data &aData,long long value);
......
......@@ -31,6 +31,7 @@ public:
struct Parameters
{
enum Mode {STANDARD,THRESHOLD_BEFORE};
Parameters();
void reset();
......@@ -39,7 +40,9 @@ public:
bool savingFlag; ///< saving flag if true save saturatedImageCounter
std::string savePrefix; ///< prefix filename of saturatedImageCounter (default is saturated_image_counter)
const char* __repr__();
Mode mode;
long long thresholdB4Acc; ///< value used in mode THRESHOLD_BEFORE
const char* __repr__();
%MethodCode
std::ostringstream str;
str << *sipCpp;
......@@ -82,6 +85,12 @@ public:
void setSavePrefix(const std::string &savePrefix);
void getSavePrefix(std::string &savePrefix /Out/) const;
void getMode(Parameters::Mode& mode) const;
void setMode(Parameters::Mode mode);
void getThresholdBeforeAcc(long long&) const;
void setThresholdBeforeAcc(const long long&);
// --- variable and data result of Concatenation or Accumulation
void readSaturatedImageCounter(Data& /Out/,long frameNumber = -1);
......
......@@ -188,7 +188,9 @@ private:
CtAccumulation::Parameters::Parameters() :
pixelThresholdValue(2^16),
savingFlag(false),
savePrefix("saturated_")
savePrefix("saturated_"),
mode(CtAccumulation::Parameters::STANDARD),
thresholdB4Acc(0)
{
reset();
}
......@@ -350,6 +352,30 @@ void CtAccumulation::getSavePrefix(std::string &savePrefix) const
savePrefix = m_pars.savePrefix;
}
void CtAccumulation::getMode(Parameters::Mode &mode) const
{
AutoMutex aLock(m_cond.mutex());
mode = m_pars.mode;
}
void CtAccumulation::setMode(Parameters::Mode mode)
{
AutoMutex aLock(m_cond.mutex());
m_pars.mode = mode;
}
void CtAccumulation::getThresholdBeforeAcc(long long& threshold) const
{
AutoMutex aLock(m_cond.mutex());
threshold = m_pars.thresholdB4Acc;
}
void CtAccumulation::setThresholdBeforeAcc(const long long& threshold)
{
AutoMutex aLock(m_cond.mutex());
m_pars.thresholdB4Acc = threshold;
}
/** @brief read the saturated image of accumulated image which id is frameNumber
@param saturatedImage the saturated image conter (empty if not yet available)
@param frameNumber the frame acquisition id
......@@ -614,12 +640,20 @@ bool CtAccumulation::_newBaseFrameReady(Data &aData)
Data saturatedImg;
if(active)
saturatedImg = m_saturated_images.back();
Parameters::Mode aMode = m_pars.mode;
long long threshold_value = m_pars.thresholdB4Acc;
aLock.unlock();
if(active)
_calcSaturatedImageNCounters(aData,saturatedImg);
_accFrame(aData,accFrame);
switch(aMode)
{
case Parameters::STANDARD:
_accFrame(aData,accFrame);break;
case Parameters::THRESHOLD_BEFORE:
_accFrameWithThreshold(aData,accFrame,threshold_value);break;
}
if(!((aData.frameNumber + 1) % nb_acc_frame))
m_last_continue_flag = m_ct.newFrameReady(accFrame);
......@@ -685,10 +719,38 @@ void CtAccumulation::_accFrame(Data &src,Data &dst)
THROW_CTL_ERROR(Error) << "Data type for accumulation is not yet managed";
}
}
template <class SrcType, class DstType>
void accumulateFrameThreshold(void *src_ptr,void *dst_ptr,int nb_items,long long threshold)
{
SrcType *sp = (SrcType *) src_ptr;
DstType *dp = (DstType *) dst_ptr;
for(int i = nb_items;i;--i,++sp,++dp)
if(*sp > threshold)
*dp += *sp;
}
void CtAccumulation::_accFrameWithThreshold(Data &src,Data &dst,long long threshold_value)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(src,dst);
int nb_items = src.dimensions[0] * src.dimensions[1];
switch(src.type)
{
case Data::UINT8: accumulateFrameThreshold<unsigned char,int> (src.data(),dst.data(),nb_items,threshold_value);break;
case Data::INT8: accumulateFrameThreshold<char,int> (src.data(),dst.data(),nb_items,threshold_value);break;
case Data::UINT16: accumulateFrameThreshold<unsigned short,int> (src.data(),dst.data(),nb_items,threshold_value);break;
case Data::INT16: accumulateFrameThreshold<short,int> (src.data(),dst.data(),nb_items,threshold_value);break;
case Data::UINT32: accumulateFrameThreshold<unsigned int,int> (src.data(),dst.data(),nb_items,threshold_value);break;
case Data::INT32: accumulateFrameThreshold<int,int> (src.data(),dst.data(),nb_items,threshold_value);break;
default:
THROW_CTL_ERROR(Error) << "Data type for accumulation is not yet managed";
}
}
#ifdef WITH_CONFIG
CtConfig::ModuleTypeCallback* CtAccumulation::_getConfigHandler()
{
return new _ConfigHandler(*this);
}
#endif //WITH_CONFIG
\ No newline at end of file
#endif //WITH_CONFIG
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment