Commit 66ee335c authored by Alexandre Benoit's avatar Alexandre Benoit

updated retina modules : minor misakes correction & changed pixel format to…

updated retina modules : minor misakes correction & changed pixel format to float instead of double to keep some memory, precision is almost sufficient, check for residual mistakes
parent eb9401d3
This diff is collapsed.
This diff is collapsed.
...@@ -394,7 +394,7 @@ bool ImageLogPolProjection::_initLogPolarCortexSampling(const double reductionFa ...@@ -394,7 +394,7 @@ bool ImageLogPolProjection::_initLogPolarCortexSampling(const double reductionFa
} }
// action function // action function
std::valarray<double> &ImageLogPolProjection::runProjection(const std::valarray<double> &inputFrame, const double colorMode) std::valarray<float> &ImageLogPolProjection::runProjection(const std::valarray<float> &inputFrame, const bool colorMode)
{ {
if (_colorModeCapable&&colorMode) if (_colorModeCapable&&colorMode)
{ {
......
...@@ -148,9 +148,10 @@ public: ...@@ -148,9 +148,10 @@ public:
/** /**
* main funtion of the class: run projection function * main funtion of the class: run projection function
* @param inputFrame: the input frame to be processed * @param inputFrame: the input frame to be processed
* @param colorMode: the input buffer color mode: false=gray levels, true = 3 color channels mode
* @return the output frame * @return the output frame
*/ */
std::valarray<double> &runProjection(const std::valarray<double> &inputFrame, const double colorMode=false); std::valarray<float> &runProjection(const std::valarray<float> &inputFrame, const bool colorMode=false);
/** /**
* @return the numbers of rows (height) of the images OUTPUTS of the object * @return the numbers of rows (height) of the images OUTPUTS of the object
...@@ -172,13 +173,13 @@ public: ...@@ -172,13 +173,13 @@ public:
/** /**
* @return the output of the filter which applies an irregular Low Pass spatial filter to the imag input (see function * @return the output of the filter which applies an irregular Low Pass spatial filter to the imag input (see function
*/ */
inline const std::valarray<double> &getIrregularLPfilteredInputFrame() const {return _irregularLPfilteredFrame;}; inline const std::valarray<float> &getIrregularLPfilteredInputFrame() const {return _irregularLPfilteredFrame;};
/** /**
* function which allows to retrieve the output frame which was updated after the "runProjection(...) function BasicRetinaFilter::runProgressiveFilter(...) * function which allows to retrieve the output frame which was updated after the "runProjection(...) function BasicRetinaFilter::runProgressiveFilter(...)
* @return the projection result * @return the projection result
*/ */
inline const std::valarray<double> &getSampledFrame() const {return _sampledFrame;}; inline const std::valarray<float> &getSampledFrame() const {return _sampledFrame;};
/** /**
* function which allows gives the tranformation table, its size is (getNBrows()*getNBcolumns()*2) * function which allows gives the tranformation table, its size is (getNBrows()*getNBcolumns()*2)
...@@ -213,11 +214,11 @@ private: ...@@ -213,11 +214,11 @@ private:
double _minDimension; double _minDimension;
// template buffers // template buffers
std::valarray<double>_sampledFrame; std::valarray<float>_sampledFrame;
std::valarray<double>&_tempBuffer; std::valarray<float>&_tempBuffer;
std::valarray<unsigned int>_transformTable; std::valarray<unsigned int>_transformTable;
std::valarray<double> &_irregularLPfilteredFrame; // just a reference for easier understanding std::valarray<float> &_irregularLPfilteredFrame; // just a reference for easier understanding
unsigned int _usefullpixelIndex; unsigned int _usefullpixelIndex;
// init transformation tables // init transformation tables
......
...@@ -142,7 +142,7 @@ void MagnoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBc ...@@ -142,7 +142,7 @@ void MagnoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBc
clearAllBuffers(); clearAllBuffers();
} }
void MagnoRetinaFilter::setCoefficientsTable(const double parasolCells_beta, const double parasolCells_tau, const double parasolCells_k, const double amacrinCellsTemporalCutFrequency, const double localAdaptIntegration_tau, const double localAdaptIntegration_k ) void MagnoRetinaFilter::setCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float localAdaptIntegration_tau, const float localAdaptIntegration_k )
{ {
_temporalCoefficient=exp(-1.0/amacrinCellsTemporalCutFrequency); _temporalCoefficient=exp(-1.0/amacrinCellsTemporalCutFrequency);
// the first set of parameters is dedicated to the low pass filtering property of the ganglion cells // the first set of parameters is dedicated to the low pass filtering property of the ganglion cells
...@@ -151,24 +151,24 @@ void MagnoRetinaFilter::setCoefficientsTable(const double parasolCells_beta, con ...@@ -151,24 +151,24 @@ void MagnoRetinaFilter::setCoefficientsTable(const double parasolCells_beta, con
BasicRetinaFilter::setLPfilterParameters(0, localAdaptIntegration_tau, localAdaptIntegration_k, 1); BasicRetinaFilter::setLPfilterParameters(0, localAdaptIntegration_tau, localAdaptIntegration_k, 1);
} }
void MagnoRetinaFilter::_amacrineCellsComputing(const double *OPL_ON, const double *OPL_OFF) void MagnoRetinaFilter::_amacrineCellsComputing(const float *OPL_ON, const float *OPL_OFF)
{ {
register const double *OPL_ON_PTR=OPL_ON; register const float *OPL_ON_PTR=OPL_ON;
register const double *OPL_OFF_PTR=OPL_OFF; register const float *OPL_OFF_PTR=OPL_OFF;
register double *previousInput_ON_PTR= &_previousInput_ON[0]; register float *previousInput_ON_PTR= &_previousInput_ON[0];
register double *previousInput_OFF_PTR= &_previousInput_OFF[0]; register float *previousInput_OFF_PTR= &_previousInput_OFF[0];
register double *amacrinCellsTempOutput_ON_PTR= &_amacrinCellsTempOutput_ON[0]; register float *amacrinCellsTempOutput_ON_PTR= &_amacrinCellsTempOutput_ON[0];
register double *amacrinCellsTempOutput_OFF_PTR= &_amacrinCellsTempOutput_OFF[0]; register float *amacrinCellsTempOutput_OFF_PTR= &_amacrinCellsTempOutput_OFF[0];
for (unsigned int IDpixel=0 ; IDpixel<this->getNBpixels(); ++IDpixel) for (unsigned int IDpixel=0 ; IDpixel<this->getNBpixels(); ++IDpixel)
{ {
/* Compute ON and OFF amacrin cells high pass temporal filter */ /* Compute ON and OFF amacrin cells high pass temporal filter */
double magnoXonPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_ON_PTR+ *OPL_ON_PTR-*previousInput_ON_PTR); float magnoXonPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_ON_PTR+ *OPL_ON_PTR-*previousInput_ON_PTR);
*(amacrinCellsTempOutput_ON_PTR++)=((double)(magnoXonPixelResult>0))*magnoXonPixelResult; *(amacrinCellsTempOutput_ON_PTR++)=((float)(magnoXonPixelResult>0))*magnoXonPixelResult;
double magnoXoffPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_OFF_PTR+ *OPL_OFF_PTR-*previousInput_OFF_PTR); float magnoXoffPixelResult = _temporalCoefficient*(*amacrinCellsTempOutput_OFF_PTR+ *OPL_OFF_PTR-*previousInput_OFF_PTR);
*(amacrinCellsTempOutput_OFF_PTR++)=((double)(magnoXoffPixelResult>0))*magnoXoffPixelResult; *(amacrinCellsTempOutput_OFF_PTR++)=((float)(magnoXoffPixelResult>0))*magnoXoffPixelResult;
/* prepare next loop */ /* prepare next loop */
*(previousInput_ON_PTR++)=*(OPL_ON_PTR++); *(previousInput_ON_PTR++)=*(OPL_ON_PTR++);
...@@ -178,7 +178,7 @@ void MagnoRetinaFilter::_amacrineCellsComputing(const double *OPL_ON, const doub ...@@ -178,7 +178,7 @@ void MagnoRetinaFilter::_amacrineCellsComputing(const double *OPL_ON, const doub
} }
// launch filter that runs all the IPL filter // launch filter that runs all the IPL filter
const std::valarray<double> &MagnoRetinaFilter::runFilter(const std::valarray<double> &OPL_ON, const std::valarray<double> &OPL_OFF) const std::valarray<float> &MagnoRetinaFilter::runFilter(const std::valarray<float> &OPL_ON, const std::valarray<float> &OPL_OFF)
{ {
// Compute the high pass temporal filter // Compute the high pass temporal filter
_amacrineCellsComputing(get_data(OPL_ON), get_data(OPL_OFF)); _amacrineCellsComputing(get_data(OPL_ON), get_data(OPL_OFF));
...@@ -194,9 +194,9 @@ const std::valarray<double> &MagnoRetinaFilter::runFilter(const std::valarray<do ...@@ -194,9 +194,9 @@ const std::valarray<double> &MagnoRetinaFilter::runFilter(const std::valarray<do
_localLuminanceAdaptation(&_magnoXOutputOFF[0], &_localProcessBufferOFF[0]); _localLuminanceAdaptation(&_magnoXOutputOFF[0], &_localProcessBufferOFF[0]);
/* Compute MagnoY */ /* Compute MagnoY */
register double *magnoYOutput= &(*_magnoYOutput)[0]; register float *magnoYOutput= &(*_magnoYOutput)[0];
register double *magnoXOutputON_PTR= &_magnoXOutputON[0]; register float *magnoXOutputON_PTR= &_magnoXOutputON[0];
register double *magnoXOutputOFF_PTR= &_magnoXOutputOFF[0]; register float *magnoXOutputOFF_PTR= &_magnoXOutputOFF[0];
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel) for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
*(magnoYOutput++)=*(magnoXOutputON_PTR++)+*(magnoXOutputOFF_PTR++); *(magnoYOutput++)=*(magnoXOutputON_PTR++)+*(magnoXOutputOFF_PTR++);
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
* movingContoursExtractor->runfilter(FrameBuffer); * movingContoursExtractor->runfilter(FrameBuffer);
* *
* // get the output frame, check in the class description below for more outputs: * // get the output frame, check in the class description below for more outputs:
* const double *movingContours=movingContoursExtractor->getMagnoYsaturated(); * const float *movingContours=movingContoursExtractor->getMagnoYsaturated();
* *
* // at the end of the program, destroy object: * // at the end of the program, destroy object:
* delete movingContoursExtractor; * delete movingContoursExtractor;
...@@ -137,7 +137,7 @@ public: ...@@ -137,7 +137,7 @@ public:
* @param localAdaptIntegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation * @param localAdaptIntegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
* @param localAdaptIntegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation * @param localAdaptIntegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
*/ */
void setCoefficientsTable(const double parasolCells_beta, const double parasolCells_tau, const double parasolCells_k, const double amacrinCellsTemporalCutFrequency, const double localAdaptIntegration_tau, const double localAdaptIntegration_k); void setCoefficientsTable(const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float localAdaptIntegration_tau, const float localAdaptIntegration_k);
/** /**
* launch filter that runs all the IPL magno filter (model of the magnocellular channel of the Inner Plexiform Layer of the retina) * launch filter that runs all the IPL magno filter (model of the magnocellular channel of the Inner Plexiform Layer of the retina)
...@@ -145,22 +145,22 @@ public: ...@@ -145,22 +145,22 @@ public:
* @param OPL_OFF: the output of the bipolar OFF cells of the retina (available from the ParvoRetinaFilter class (getBipolarCellsOFF() function) * @param OPL_OFF: the output of the bipolar OFF cells of the retina (available from the ParvoRetinaFilter class (getBipolarCellsOFF() function)
* @return the processed result without post-processing * @return the processed result without post-processing
*/ */
const std::valarray<double> &runFilter(const std::valarray<double> &OPL_ON, const std::valarray<double> &OPL_OFF); const std::valarray<float> &runFilter(const std::valarray<float> &OPL_ON, const std::valarray<float> &OPL_OFF);
/** /**
* @return the Magnocellular ON channel filtering output * @return the Magnocellular ON channel filtering output
*/ */
inline const std::valarray<double> &getMagnoON() const {return _magnoXOutputON;}; inline const std::valarray<float> &getMagnoON() const {return _magnoXOutputON;};
/** /**
* @return the Magnocellular OFF channel filtering output * @return the Magnocellular OFF channel filtering output
*/ */
inline const std::valarray<double> &getMagnoOFF() const {return _magnoXOutputOFF;}; inline const std::valarray<float> &getMagnoOFF() const {return _magnoXOutputOFF;};
/** /**
* @return the Magnocellular Y (sum of the ON and OFF magno channels) filtering output * @return the Magnocellular Y (sum of the ON and OFF magno channels) filtering output
*/ */
inline const std::valarray<double> &getMagnoYsaturated() const {return *_magnoYsaturated;}; inline const std::valarray<float> &getMagnoYsaturated() const {return *_magnoYsaturated;};
/** /**
* applies an image normalization which saturates the high output values by the use of an assymetric sigmoide * applies an image normalization which saturates the high output values by the use of an assymetric sigmoide
...@@ -170,28 +170,28 @@ public: ...@@ -170,28 +170,28 @@ public:
/** /**
* @return the horizontal cells' temporal constant * @return the horizontal cells' temporal constant
*/ */
inline const double getTemporalConstant(){return this->_filteringCoeficientsTable[2];}; inline const float getTemporalConstant(){return this->_filteringCoeficientsTable[2];};
private: private:
// related pointers to these buffers // related pointers to these buffers
std::valarray<double> _previousInput_ON; std::valarray<float> _previousInput_ON;
std::valarray<double> _previousInput_OFF; std::valarray<float> _previousInput_OFF;
std::valarray<double> _amacrinCellsTempOutput_ON; std::valarray<float> _amacrinCellsTempOutput_ON;
std::valarray<double> _amacrinCellsTempOutput_OFF; std::valarray<float> _amacrinCellsTempOutput_OFF;
std::valarray<double> _magnoXOutputON; std::valarray<float> _magnoXOutputON;
std::valarray<double> _magnoXOutputOFF; std::valarray<float> _magnoXOutputOFF;
std::valarray<double> _localProcessBufferON; std::valarray<float> _localProcessBufferON;
std::valarray<double> _localProcessBufferOFF; std::valarray<float> _localProcessBufferOFF;
// reference to parent buffers and allow better readability // reference to parent buffers and allow better readability
TemplateBuffer<double> *_magnoYOutput; TemplateBuffer<float> *_magnoYOutput;
std::valarray<double> *_magnoYsaturated; std::valarray<float> *_magnoYsaturated;
// varialbles // varialbles
double _temporalCoefficient; float _temporalCoefficient;
// amacrine cells filter : high pass temporal filter // amacrine cells filter : high pass temporal filter
void _amacrineCellsComputing(const double *ONinput, const double *OFFinput); void _amacrineCellsComputing(const float *ONinput, const float *OFFinput);
}; };
......
...@@ -155,7 +155,7 @@ void ParvoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBc ...@@ -155,7 +155,7 @@ void ParvoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBc
} }
// change the parameters of the filter // change the parameters of the filter
void ParvoRetinaFilter::setOPLandParvoFiltersParameters(const double beta1, const double tau1, const double k1, const double beta2, const double tau2, const double k2) void ParvoRetinaFilter::setOPLandParvoFiltersParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2)
{ {
// init photoreceptors low pass filter // init photoreceptors low pass filter
setLPfilterParameters(beta1, tau1, k1); setLPfilterParameters(beta1, tau1, k1);
...@@ -170,7 +170,7 @@ void ParvoRetinaFilter::setOPLandParvoFiltersParameters(const double beta1, cons ...@@ -170,7 +170,7 @@ void ParvoRetinaFilter::setOPLandParvoFiltersParameters(const double beta1, cons
// run filter for a new frame input // run filter for a new frame input
// output return is (*_parvocellularOutputONminusOFF) // output return is (*_parvocellularOutputONminusOFF)
const std::valarray<double> &ParvoRetinaFilter::runFilter(const std::valarray<double> &inputFrame, const bool useParvoOutput) const std::valarray<float> &ParvoRetinaFilter::runFilter(const std::valarray<float> &inputFrame, const bool useParvoOutput)
{ {
_spatiotemporalLPfilter(get_data(inputFrame), &_photoreceptorsOutput[0]); _spatiotemporalLPfilter(get_data(inputFrame), &_photoreceptorsOutput[0]);
_spatiotemporalLPfilter(&_photoreceptorsOutput[0], &_horizontalCellsOutput[0], 1); _spatiotemporalLPfilter(&_photoreceptorsOutput[0], &_horizontalCellsOutput[0], 1);
...@@ -189,9 +189,9 @@ const std::valarray<double> &ParvoRetinaFilter::runFilter(const std::valarray<do ...@@ -189,9 +189,9 @@ const std::valarray<double> &ParvoRetinaFilter::runFilter(const std::valarray<do
// //
//// loop that makes the difference between photoreceptor cells output and horizontal cells //// loop that makes the difference between photoreceptor cells output and horizontal cells
//// positive part goes on the ON way, negative pat goes on the OFF way //// positive part goes on the ON way, negative pat goes on the OFF way
register double *parvocellularOutputONminusOFF_PTR=&(*_parvocellularOutputONminusOFF)[0]; register float *parvocellularOutputONminusOFF_PTR=&(*_parvocellularOutputONminusOFF)[0];
register double *parvocellularOutputON_PTR=&_parvocellularOutputON[0]; register float *parvocellularOutputON_PTR=&_parvocellularOutputON[0];
register double *parvocellularOutputOFF_PTR=&_parvocellularOutputOFF[0]; register float *parvocellularOutputOFF_PTR=&_parvocellularOutputOFF[0];
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel) for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
*(parvocellularOutputONminusOFF_PTR++)= (*(parvocellularOutputON_PTR++)-*(parvocellularOutputOFF_PTR++)); *(parvocellularOutputONminusOFF_PTR++)= (*(parvocellularOutputON_PTR++)-*(parvocellularOutputOFF_PTR++));
...@@ -203,20 +203,20 @@ void ParvoRetinaFilter::_OPL_OnOffWaysComputing() ...@@ -203,20 +203,20 @@ void ParvoRetinaFilter::_OPL_OnOffWaysComputing()
{ {
// loop that makes the difference between photoreceptor cells output and horizontal cells // loop that makes the difference between photoreceptor cells output and horizontal cells
// positive part goes on the ON way, negative pat goes on the OFF way // positive part goes on the ON way, negative pat goes on the OFF way
register double *photoreceptorsOutput_PTR= &_photoreceptorsOutput[0]; register float *photoreceptorsOutput_PTR= &_photoreceptorsOutput[0];
register double *horizontalCellsOutput_PTR= &_horizontalCellsOutput[0]; register float *horizontalCellsOutput_PTR= &_horizontalCellsOutput[0];
register double *bipolarCellsON_PTR = &_bipolarCellsOutputON[0]; register float *bipolarCellsON_PTR = &_bipolarCellsOutputON[0];
register double *bipolarCellsOFF_PTR = &_bipolarCellsOutputOFF[0]; register float *bipolarCellsOFF_PTR = &_bipolarCellsOutputOFF[0];
register double *parvocellularOutputON_PTR= &_parvocellularOutputON[0]; register float *parvocellularOutputON_PTR= &_parvocellularOutputON[0];
register double *parvocellularOutputOFF_PTR= &_parvocellularOutputOFF[0]; register float *parvocellularOutputOFF_PTR= &_parvocellularOutputOFF[0];
// compute bipolar cells response equal to photoreceptors minus horizontal cells response // compute bipolar cells response equal to photoreceptors minus horizontal cells response
// and copy the result on parvo cellular outputs... keeping time before their local contrast adaptation for final result // and copy the result on parvo cellular outputs... keeping time before their local contrast adaptation for final result
for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel) for (register unsigned int IDpixel=0 ; IDpixel<_filterOutput.getNBpixels() ; ++IDpixel)
{ {
double pixelDifference = *(photoreceptorsOutput_PTR++) -*(horizontalCellsOutput_PTR++); float pixelDifference = *(photoreceptorsOutput_PTR++) -*(horizontalCellsOutput_PTR++);
// test condition to allow write pixelDifference in ON or OFF buffer and 0 in the over // test condition to allow write pixelDifference in ON or OFF buffer and 0 in the over
double isPositive=(double) (pixelDifference>0); float isPositive=(float) (pixelDifference>0);
// ON and OFF channels writing step // ON and OFF channels writing step
*(parvocellularOutputON_PTR++)=*(bipolarCellsON_PTR++) = isPositive*pixelDifference; *(parvocellularOutputON_PTR++)=*(bipolarCellsON_PTR++) = isPositive*pixelDifference;
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
* contoursExtractor->runfilter(FrameBuffer); * contoursExtractor->runfilter(FrameBuffer);
* *
* // get the output frame, check in the class description below for more outputs: * // get the output frame, check in the class description below for more outputs:
* const double *contours=contoursExtractor->getParvoONminusOFF(); * const float *contours=contoursExtractor->getParvoONminusOFF();
* *
* // at the end of the program, destroy object: * // at the end of the program, destroy object:
* delete contoursExtractor; * delete contoursExtractor;
...@@ -141,14 +141,14 @@ public: ...@@ -141,14 +141,14 @@ public:
* @param tau2: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors * @param tau2: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
* @param k2: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model) * @param k2: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
*/ */
void setOPLandParvoFiltersParameters(const double beta1, const double tau1, const double k1, const double beta2, const double tau2, const double k2); void setOPLandParvoFiltersParameters(const float beta1, const float tau1, const float k1, const float beta2, const float tau2, const float k2);
/** /**
* setup more precisely the low pass filter used for the ganglion cells low pass filtering (used for local luminance adaptation) * setup more precisely the low pass filter used for the ganglion cells low pass filtering (used for local luminance adaptation)
* @param tau: time constant of the filter (unit is frame for video processing) * @param tau: time constant of the filter (unit is frame for video processing)
* @param k: spatial constant of the filter (unit is pixels) * @param k: spatial constant of the filter (unit is pixels)
*/ */
void setGanglionCellsLocalAdaptationLPfilterParameters(const double tau, const double k){BasicRetinaFilter::setLPfilterParameters(0, tau, k, 2);}; // change the parameters of the filter void setGanglionCellsLocalAdaptationLPfilterParameters(const float tau, const float k){BasicRetinaFilter::setLPfilterParameters(0, tau, k, 2);}; // change the parameters of the filter
/** /**
...@@ -160,59 +160,59 @@ public: ...@@ -160,59 +160,59 @@ public:
* also, bipolar cells output are accessible (difference between photoreceptors and horizontal cells, ON output has positive values, OFF ouput has negative values), use the following access methods: getBipolarCellsON() and getBipolarCellsOFF()if useParvoOutput is true, * also, bipolar cells output are accessible (difference between photoreceptors and horizontal cells, ON output has positive values, OFF ouput has negative values), use the following access methods: getBipolarCellsON() and getBipolarCellsOFF()if useParvoOutput is true,
* if useParvoOutput is true, the complete Parvocellular channel is computed, more outputs are updated and can be accessed threw: getParvoON(), getParvoOFF() and their difference with getOutput() * if useParvoOutput is true, the complete Parvocellular channel is computed, more outputs are updated and can be accessed threw: getParvoON(), getParvoOFF() and their difference with getOutput()
*/ */
const std::valarray<double> &runFilter(const std::valarray<double> &inputFrame, const bool useParvoOutput=true); // output return is _parvocellularOutputONminusOFF const std::valarray<float> &runFilter(const std::valarray<float> &inputFrame, const bool useParvoOutput=true); // output return is _parvocellularOutputONminusOFF
/** /**
* @return the output of the photoreceptors filtering step (high cut frequency spatio-temporal low pass filter) * @return the output of the photoreceptors filtering step (high cut frequency spatio-temporal low pass filter)
*/ */
inline const std::valarray<double> &getPhotoreceptorsLPfilteringOutput() const {return _photoreceptorsOutput;}; inline const std::valarray<float> &getPhotoreceptorsLPfilteringOutput() const {return _photoreceptorsOutput;};
/** /**
* @return the output of the photoreceptors filtering step (low cut frequency spatio-temporal low pass filter) * @return the output of the photoreceptors filtering step (low cut frequency spatio-temporal low pass filter)
*/ */
inline const std::valarray<double> &getHorizontalCellsOutput() const { return _horizontalCellsOutput;}; inline const std::valarray<float> &getHorizontalCellsOutput() const { return _horizontalCellsOutput;};
/** /**
* @return the output Parvocellular ON channel of the retina model * @return the output Parvocellular ON channel of the retina model
*/ */
inline const std::valarray<double> &getParvoON() const {return _parvocellularOutputON;}; inline const std::valarray<float> &getParvoON() const {return _parvocellularOutputON;};
/** /**
* @return the output Parvocellular OFF channel of the retina model * @return the output Parvocellular OFF channel of the retina model
*/ */
inline const std::valarray<double> &getParvoOFF() const {return _parvocellularOutputOFF;}; inline const std::valarray<float> &getParvoOFF() const {return _parvocellularOutputOFF;};
/** /**
* @return the output of the Bipolar cells of the ON channel of the retina model same as function getParvoON() but without luminance local adaptation * @return the output of the Bipolar cells of the ON channel of the retina model same as function getParvoON() but without luminance local adaptation
*/ */
inline const std::valarray<double> &getBipolarCellsON() const {return _bipolarCellsOutputON;}; inline const std::valarray<float> &getBipolarCellsON() const {return _bipolarCellsOutputON;};
/** /**
* @return the output of the Bipolar cells of the OFF channel of the retina model same as function getParvoON() but without luminance local adaptation * @return the output of the Bipolar cells of the OFF channel of the retina model same as function getParvoON() but without luminance local adaptation
*/ */
inline const std::valarray<double> &getBipolarCellsOFF() const {return _bipolarCellsOutputOFF;}; inline const std::valarray<float> &getBipolarCellsOFF() const {return _bipolarCellsOutputOFF;};
/** /**
* @return the photoreceptors's temporal constant * @return the photoreceptors's temporal constant
*/ */
inline const double getPhotoreceptorsTemporalConstant(){return this->_filteringCoeficientsTable[2];}; inline const float getPhotoreceptorsTemporalConstant(){return this->_filteringCoeficientsTable[2];};
/** /**
* @return the horizontal cells' temporal constant * @return the horizontal cells' temporal constant
*/ */
inline const double getHcellsTemporalConstant(){return this->_filteringCoeficientsTable[5];}; inline const float getHcellsTemporalConstant(){return this->_filteringCoeficientsTable[5];};
private: private:
// template buffers // template buffers
std::valarray <double>_photoreceptorsOutput; std::valarray <float>_photoreceptorsOutput;
std::valarray <double>_horizontalCellsOutput; std::valarray <float>_horizontalCellsOutput;
std::valarray <double>_parvocellularOutputON; std::valarray <float>_parvocellularOutputON;
std::valarray <double>_parvocellularOutputOFF; std::valarray <float>_parvocellularOutputOFF;
std::valarray <double>_bipolarCellsOutputON; std::valarray <float>_bipolarCellsOutputON;
std::valarray <double>_bipolarCellsOutputOFF; std::valarray <float>_bipolarCellsOutputOFF;
std::valarray <double>_localAdaptationOFF; std::valarray <float>_localAdaptationOFF;
std::valarray <double> *_localAdaptationON; std::valarray <float> *_localAdaptationON;
TemplateBuffer<double> *_parvocellularOutputONminusOFF; TemplateBuffer<float> *_parvocellularOutputONminusOFF;
// private functions // private functions
void _OPL_OnOffWaysComputing(); void _OPL_OnOffWaysComputing();
......
...@@ -92,7 +92,7 @@ Retina::~Retina() ...@@ -92,7 +92,7 @@ Retina::~Retina()
delete _retinaFilter; delete _retinaFilter;
} }
void Retina::setColorSaturation(const bool saturateColors, const double colorSaturationValue) void Retina::setColorSaturation(const bool saturateColors, const float colorSaturationValue)
{ {
_retinaFilter->setColorSaturation(saturateColors, colorSaturationValue); _retinaFilter->setColorSaturation(saturateColors, colorSaturationValue);
} }
...@@ -123,7 +123,7 @@ void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetup ...@@ -123,7 +123,7 @@ void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetup
// preparing parameter setup // preparing parameter setup
bool colorMode, normaliseOutput; bool colorMode, normaliseOutput;
double photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
// OPL and Parvo init first // OPL and Parvo init first
cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"]; cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"];
currFn["colorMode"]>>colorMode; currFn["colorMode"]>>colorMode;
...@@ -140,7 +140,7 @@ void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetup ...@@ -140,7 +140,7 @@ void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetup
// init retina IPL magno setup // init retina IPL magno setup
currFn=rootFn["IPLmagno"]; currFn=rootFn["IPLmagno"];
currFn["normaliseOutput"]>>normaliseOutput; currFn["normaliseOutput"]>>normaliseOutput;
double parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k;
currFn["parasolCells_beta"]>>parasolCells_beta; currFn["parasolCells_beta"]>>parasolCells_beta;
currFn["parasolCells_tau"]>>parasolCells_tau; currFn["parasolCells_tau"]>>parasolCells_tau;
currFn["parasolCells_k"]>>parasolCells_k; currFn["parasolCells_k"]>>parasolCells_k;
...@@ -221,7 +221,7 @@ const std::string Retina::printSetup() ...@@ -221,7 +221,7 @@ const std::string Retina::printSetup()
return outmessage.str(); return outmessage.str();
} }
void Retina::setupOPLandIPLParvoChannel(const bool colorMode, const bool normaliseOutput, const double photoreceptorsLocalAdaptationSensitivity, const double photoreceptorsTemporalConstant, const double photoreceptorsSpatialConstant, const double horizontalCellsGain, const double HcellsTemporalConstant, const double HcellsSpatialConstant, const double ganglionCellsSensitivity) void Retina::setupOPLandIPLParvoChannel(const bool colorMode, const bool normaliseOutput, const float photoreceptorsLocalAdaptationSensitivity, const float photoreceptorsTemporalConstant, const float photoreceptorsSpatialConstant, const float horizontalCellsGain, const float HcellsTemporalConstant, const float HcellsSpatialConstant, const float ganglionCellsSensitivity)
{ {
// parameters setup (default setup) // parameters setup (default setup)
_retinaFilter->setColorMode(colorMode); _retinaFilter->setColorMode(colorMode);
...@@ -246,7 +246,7 @@ void Retina::setupOPLandIPLParvoChannel(const bool colorMode, const bool normali ...@@ -246,7 +246,7 @@ void Retina::setupOPLandIPLParvoChannel(const bool colorMode, const bool normali
_parametersSaveFile << "}"; _parametersSaveFile << "}";
} }
void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const double parasolCells_beta, const double parasolCells_tau, const double parasolCells_k, const double amacrinCellsTemporalCutFrequency, const double V0CompressionParameter, const double localAdaptintegration_tau, const double localAdaptintegration_k) void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float V0CompressionParameter, const float localAdaptintegration_tau, const float localAdaptintegration_k)
{ {
_retinaFilter->setMagnoCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k); _retinaFilter->setMagnoCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k);
...@@ -270,7 +270,7 @@ void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const double paras ...@@ -270,7 +270,7 @@ void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const double paras
void Retina::run(const cv::Mat &inputMatToConvert) void Retina::run(const cv::Mat &inputMatToConvert)
{ {
// first convert input image to the compatible format : std::valarray<double> // first convert input image to the compatible format : std::valarray<float>
const bool colorMode = _convertCvMat2ValarrayBuffer(inputMatToConvert, _inputBuffer); const bool colorMode = _convertCvMat2ValarrayBuffer(inputMatToConvert, _inputBuffer);
// process the retina // process the retina
if (!_retinaFilter->runFilter(_inputBuffer, colorMode, false, colorMode, false)) if (!_retinaFilter->runFilter(_inputBuffer, colorMode, false, colorMode, false))
...@@ -338,10 +338,10 @@ void Retina::_init(const std::string parametersSaveFile, const cv::Size inputSiz ...@@ -338,10 +338,10 @@ void Retina::_init(const std::string parametersSaveFile, const cv::Size inputSiz
std::cout<<printSetup()<<std::endl; std::cout<<printSetup()<<std::endl;
} }
void Retina::_convertValarrayBuffer2cvMat(const std::valarray<double> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, cv::Mat &outBuffer) void Retina::_convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, cv::Mat &outBuffer)
{ {
// fill output buffer with the valarray buffer // fill output buffer with the valarray buffer
const double *valarrayPTR=get_data(grayMatrixToConvert); const float *valarrayPTR=get_data(grayMatrixToConvert);
if (!colorMode) if (!colorMode)
{ {
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8U); outBuffer.create(cv::Size(nbColumns, nbRows), CV_8U);
...@@ -373,8 +373,7 @@ void Retina::_convertValarrayBuffer2cvMat(const std::valarray<double> &grayMatri ...@@ -373,8 +373,7 @@ void Retina::_convertValarrayBuffer2cvMat(const std::valarray<double> &grayMatri
} }
} }
const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std::valarray<float> &outputValarrayMatrix)
const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std::valarray<double> &outputValarrayMatrix)
{ {
// first check input consistency // first check input consistency
if (inputMatToConvert.empty()) if (inputMatToConvert.empty())
...@@ -383,9 +382,8 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, ...@@ -383,9 +382,8 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert,
// retreive color mode from image input // retreive color mode from image input
bool colorMode = inputMatToConvert.channels() >=3; bool colorMode = inputMatToConvert.channels() >=3;
// convert to double AND fill the valarray buffer // convert to float AND fill the valarray buffer
const int dsttype = CV_64F; // output buffer is double format const int dsttype = CV_32F; // output buffer is float format
if (colorMode) if (colorMode)
{ {
// create a cv::Mat table (for RGB planes) // create a cv::Mat table (for RGB planes)
...@@ -396,12 +394,12 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, ...@@ -396,12 +394,12 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert,
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]) cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
}; };
// split color cv::Mat in 3 planes... it fills valarray directely // split color cv::Mat in 3 planes... it fills valarray directely
cv::split(Mat_<double>(inputMatToConvert), planes); cv::split(cv::Mat(inputMatToConvert), planes);
}else }else
{ {
// create a cv::Mat header for the valarray // create a cv::Mat header for the valarray
cv::Mat dst(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]); cv::Mat dst(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]);
inputMatToConvert.convertTo(dst, dsttype); inputMatToConvert.convertTo(dst, dsttype);
} }
return colorMode; return colorMode;
...@@ -410,3 +408,4 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, ...@@ -410,3 +408,4 @@ const bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert,
void Retina::clearBuffers() {_retinaFilter->clearAllBuffers();} void Retina::clearBuffers() {_retinaFilter->clearAllBuffers();}
} // end of namespace cv } // end of namespace cv
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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