|
|
|
@@ -73,9 +73,9 @@
|
|
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
|
{
|
|
|
|
|
// standard constructor without any log sampling of the input frame
|
|
|
|
|
RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode, const RETINA_COLORSAMPLINGMETHOD samplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
|
|
|
|
:
|
|
|
|
|
// standard constructor without any log sampling of the input frame
|
|
|
|
|
RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode, const RETINA_COLORSAMPLINGMETHOD samplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
|
|
|
|
:
|
|
|
|
|
_retinaParvoMagnoMappedFrame(0),
|
|
|
|
|
_retinaParvoMagnoMapCoefTable(0),
|
|
|
|
|
_photoreceptorsPrefilter((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor), 4),
|
|
|
|
@@ -84,7 +84,7 @@ RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeC
|
|
|
|
|
_colorEngine((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor), samplingMethod),
|
|
|
|
|
// configure retina photoreceptors log sampling... if necessary
|
|
|
|
|
_photoreceptorsLogSampling(NULL)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#ifdef RETINADEBUG
|
|
|
|
|
std::cout<<"RetinaFilter::size( "<<_photoreceptorsPrefilter.getNBrows()<<", "<<_photoreceptorsPrefilter.getNBcolumns()<<")"<<" =? "<<_photoreceptorsPrefilter.getNBpixels()<<std::endl;
|
|
|
|
@@ -128,18 +128,18 @@ RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeC
|
|
|
|
|
|
|
|
|
|
// std::cout<<"RetinaFilter::size( "<<this->getNBrows()<<", "<<this->getNBcolumns()<<")"<<_filterOutput.size()<<" =? "<<_filterOutput.getNBpixels()<<std::endl;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// destructor
|
|
|
|
|
RetinaFilter::~RetinaFilter()
|
|
|
|
|
{
|
|
|
|
|
// destructor
|
|
|
|
|
RetinaFilter::~RetinaFilter()
|
|
|
|
|
{
|
|
|
|
|
if (_photoreceptorsLogSampling!=NULL)
|
|
|
|
|
delete _photoreceptorsLogSampling;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// function that clears all buffers of the object
|
|
|
|
|
void RetinaFilter::clearAllBuffers()
|
|
|
|
|
{
|
|
|
|
|
// function that clears all buffers of the object
|
|
|
|
|
void RetinaFilter::clearAllBuffers()
|
|
|
|
|
{
|
|
|
|
|
_photoreceptorsPrefilter.clearAllBuffers();
|
|
|
|
|
_ParvoRetinaFilter.clearAllBuffers();
|
|
|
|
|
_MagnoRetinaFilter.clearAllBuffers();
|
|
|
|
@@ -148,15 +148,15 @@ void RetinaFilter::clearAllBuffers()
|
|
|
|
|
_photoreceptorsLogSampling->clearAllBuffers();
|
|
|
|
|
// stability controls value init
|
|
|
|
|
_setInitPeriodCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* resize retina filter object (resize all allocated buffers
|
|
|
|
|
* @param NBrows: the new height size
|
|
|
|
|
* @param NBcolumns: the new width size
|
|
|
|
|
*/
|
|
|
|
|
void RetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* resize retina filter object (resize all allocated buffers
|
|
|
|
|
* @param NBrows: the new height size
|
|
|
|
|
* @param NBcolumns: the new width size
|
|
|
|
|
*/
|
|
|
|
|
void RetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns)
|
|
|
|
|
{
|
|
|
|
|
unsigned int rows=NBrows, cols=NBcolumns;
|
|
|
|
|
|
|
|
|
|
// resize optionnal member and adjust other modules size if required
|
|
|
|
@@ -178,21 +178,21 @@ void RetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumn
|
|
|
|
|
// clean buffers
|
|
|
|
|
clearAllBuffers();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stability controls value init
|
|
|
|
|
void RetinaFilter::_setInitPeriodCount()
|
|
|
|
|
{
|
|
|
|
|
// stability controls value init
|
|
|
|
|
void RetinaFilter::_setInitPeriodCount()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// find out the maximum temporal constant value and apply a security factor
|
|
|
|
|
// false value (obviously too long) but appropriate for simple use
|
|
|
|
|
_globalTemporalConstant=(unsigned int)(_ParvoRetinaFilter.getPhotoreceptorsTemporalConstant()+_ParvoRetinaFilter.getHcellsTemporalConstant()+_MagnoRetinaFilter.getTemporalConstant());
|
|
|
|
|
// reset frame counter
|
|
|
|
|
_ellapsedFramesSinceLastReset=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RetinaFilter::_createHybridTable()
|
|
|
|
|
{
|
|
|
|
|
void RetinaFilter::_createHybridTable()
|
|
|
|
|
{
|
|
|
|
|
// create hybrid output and related coefficient table
|
|
|
|
|
_retinaParvoMagnoMappedFrame.resize(_photoreceptorsPrefilter.getNBpixels());
|
|
|
|
|
|
|
|
|
@@ -218,11 +218,11 @@ void RetinaFilter::_createHybridTable()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setup parameters function and global data filling
|
|
|
|
|
void RetinaFilter::setGlobalParameters(const float OPLspatialResponse1, const float OPLtemporalresponse1, const float OPLassymetryGain, const float OPLspatialResponse2, const float OPLtemporalresponse2, const float LPfilterSpatialResponse, const float LPfilterGain, const float LPfilterTemporalresponse, const float MovingContoursExtractorCoefficient, const bool normalizeParvoOutput_0_maxOutputValue, const bool normalizeMagnoOutput_0_maxOutputValue, const float maxOutputValue, const float maxInputValue, const float meanValue)
|
|
|
|
|
{
|
|
|
|
|
// setup parameters function and global data filling
|
|
|
|
|
void RetinaFilter::setGlobalParameters(const float OPLspatialResponse1, const float OPLtemporalresponse1, const float OPLassymetryGain, const float OPLspatialResponse2, const float OPLtemporalresponse2, const float LPfilterSpatialResponse, const float LPfilterGain, const float LPfilterTemporalresponse, const float MovingContoursExtractorCoefficient, const bool normalizeParvoOutput_0_maxOutputValue, const bool normalizeMagnoOutput_0_maxOutputValue, const float maxOutputValue, const float maxInputValue, const float meanValue)
|
|
|
|
|
{
|
|
|
|
|
_normalizeParvoOutput_0_maxOutputValue=normalizeParvoOutput_0_maxOutputValue;
|
|
|
|
|
_normalizeMagnoOutput_0_maxOutputValue=normalizeMagnoOutput_0_maxOutputValue;
|
|
|
|
|
_maxOutputValue=maxOutputValue;
|
|
|
|
@@ -238,10 +238,10 @@ void RetinaFilter::setGlobalParameters(const float OPLspatialResponse1, const fl
|
|
|
|
|
|
|
|
|
|
// stability controls value init
|
|
|
|
|
_setInitPeriodCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool RetinaFilter::checkInput(const std::valarray<float> &input, const bool)
|
|
|
|
|
{
|
|
|
|
|
const bool RetinaFilter::checkInput(const std::valarray<float> &input, const bool)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
BasicRetinaFilter *inputTarget=&_photoreceptorsPrefilter;
|
|
|
|
|
if (_photoreceptorsLogSampling)
|
|
|
|
@@ -256,11 +256,11 @@ const bool RetinaFilter::checkInput(const std::valarray<float> &input, const boo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// main function that runs the filter for a given input frame
|
|
|
|
|
const bool RetinaFilter::runFilter(const std::valarray<float> &imageInput, const bool useAdaptiveFiltering, const bool processRetinaParvoMagnoMapping, const bool useColorMode, const bool inputIsColorMultiplexed)
|
|
|
|
|
{
|
|
|
|
|
// main function that runs the filter for a given input frame
|
|
|
|
|
const bool RetinaFilter::runFilter(const std::valarray<float> &imageInput, const bool useAdaptiveFiltering, const bool processRetinaParvoMagnoMapping, const bool useColorMode, const bool inputIsColorMultiplexed)
|
|
|
|
|
{
|
|
|
|
|
// preliminary check
|
|
|
|
|
bool processSuccess=true;
|
|
|
|
|
if (!checkInput(imageInput, useColorMode))
|
|
|
|
@@ -344,29 +344,29 @@ const bool RetinaFilter::runFilter(const std::valarray<float> &imageInput, const
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return processSuccess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::valarray<float> &RetinaFilter::getContours()
|
|
|
|
|
{
|
|
|
|
|
const std::valarray<float> &RetinaFilter::getContours()
|
|
|
|
|
{
|
|
|
|
|
if (_useColorMode)
|
|
|
|
|
return _colorEngine.getLuminance();
|
|
|
|
|
else
|
|
|
|
|
return _ParvoRetinaFilter.getOutput();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
// preliminary check
|
|
|
|
|
if (!checkInput(grayImageInput, false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this->_runGrayToneMapping(grayImageInput, grayImageOutput, PhotoreceptorsCompression, ganglionCellsCompression);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::_runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::_runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
// stability controls value update
|
|
|
|
|
++_ellapsedFramesSinceLastReset;
|
|
|
|
|
|
|
|
|
@@ -389,10 +389,10 @@ void RetinaFilter::_runGrayToneMapping(const std::valarray<float> &grayImageInpu
|
|
|
|
|
_photoreceptorsPrefilter.setV0CompressionParameterToneMapping(ganglionCellsCompression, temp2.max(), temp2.sum()/(float)_photoreceptorsPrefilter.getNBpixels());
|
|
|
|
|
_photoreceptorsPrefilter.runFilter_LocalAdapdation(temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// run the initilized retina filter in order to perform color tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::runRGBToneMapping(const std::valarray<float> &RGBimageInput, std::valarray<float> &RGBimageOutput, const bool useAdaptiveFiltering, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// run the initilized retina filter in order to perform color tone mapping, after this call all retina outputs are updated
|
|
|
|
|
void RetinaFilter::runRGBToneMapping(const std::valarray<float> &RGBimageInput, std::valarray<float> &RGBimageOutput, const bool useAdaptiveFiltering, const float PhotoreceptorsCompression, const float ganglionCellsCompression)
|
|
|
|
|
{
|
|
|
|
|
// preliminary check
|
|
|
|
|
if (!checkInput(RGBimageInput, true))
|
|
|
|
|
return;
|
|
|
|
@@ -411,10 +411,10 @@ void RetinaFilter::runRGBToneMapping(const std::valarray<float> &RGBimageInput,
|
|
|
|
|
|
|
|
|
|
// return the result
|
|
|
|
|
RGBimageOutput=_colorEngine.getDemultiplexedColorFrame();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RetinaFilter::runLMSToneMapping(const std::valarray<float> &, std::valarray<float> &, const bool, const float, const float)
|
|
|
|
|
{
|
|
|
|
|
void RetinaFilter::runLMSToneMapping(const std::valarray<float> &, std::valarray<float> &, const bool, const float, const float)
|
|
|
|
|
{
|
|
|
|
|
std::cerr<<"not working, sorry"<<std::endl;
|
|
|
|
|
|
|
|
|
|
/* // preliminary check
|
|
|
|
@@ -468,11 +468,11 @@ void RetinaFilter::runLMSToneMapping(const std::valarray<float> &, std::valarray
|
|
|
|
|
// rewrite output to the appropriate buffer
|
|
|
|
|
_colorEngine->setDemultiplexedColorFrame(lmsTempBuffer.Buffer());
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return image with center Parvo and peripheral Magno channels
|
|
|
|
|
void RetinaFilter::_processRetinaParvoMagnoMapping()
|
|
|
|
|
{
|
|
|
|
|
// return image with center Parvo and peripheral Magno channels
|
|
|
|
|
void RetinaFilter::_processRetinaParvoMagnoMapping()
|
|
|
|
|
{
|
|
|
|
|
register float *hybridParvoMagnoPTR= &_retinaParvoMagnoMappedFrame[0];
|
|
|
|
|
register const float *parvoOutputPTR= get_data(_ParvoRetinaFilter.getOutput());
|
|
|
|
|
register const float *magnoXOutputPTR= get_data(_MagnoRetinaFilter.getOutput());
|
|
|
|
@@ -486,10 +486,10 @@ void RetinaFilter::_processRetinaParvoMagnoMapping()
|
|
|
|
|
|
|
|
|
|
TemplateBuffer<float>::normalizeGrayOutput_0_maxOutputValue(&_retinaParvoMagnoMappedFrame[0], _photoreceptorsPrefilter.getNBpixels());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool RetinaFilter::getParvoFoveaResponse(std::valarray<float> &parvoFovealResponse)
|
|
|
|
|
{
|
|
|
|
|
const bool RetinaFilter::getParvoFoveaResponse(std::valarray<float> &parvoFovealResponse)
|
|
|
|
|
{
|
|
|
|
|
if (!_useParvoOutput)
|
|
|
|
|
return false;
|
|
|
|
|
if (parvoFovealResponse.size() != _ParvoRetinaFilter.getNBpixels())
|
|
|
|
@@ -505,11 +505,11 @@ const bool RetinaFilter::getParvoFoveaResponse(std::valarray<float> &parvoFoveal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// method to retrieve the parafoveal magnocellular pathway response (no energy motion in fovea)
|
|
|
|
|
const bool RetinaFilter::getMagnoParaFoveaResponse(std::valarray<float> &magnoParafovealResponse)
|
|
|
|
|
{
|
|
|
|
|
// method to retrieve the parafoveal magnocellular pathway response (no energy motion in fovea)
|
|
|
|
|
const bool RetinaFilter::getMagnoParaFoveaResponse(std::valarray<float> &magnoParafovealResponse)
|
|
|
|
|
{
|
|
|
|
|
if (!_useMagnoOutput)
|
|
|
|
|
return false;
|
|
|
|
|
if (magnoParafovealResponse.size() != _MagnoRetinaFilter.getNBpixels())
|
|
|
|
@@ -525,7 +525,5 @@ const bool RetinaFilter::getMagnoParaFoveaResponse(std::valarray<float> &magnoPa
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|