diff --git a/modules/bioinspired/samples/OpenEXRimages_HDR_Retina_toneMapping.cpp b/modules/bioinspired/samples/OpenEXRimages_HDR_Retina_toneMapping.cpp index 66cae7719..622b210ae 100644 --- a/modules/bioinspired/samples/OpenEXRimages_HDR_Retina_toneMapping.cpp +++ b/modules/bioinspired/samples/OpenEXRimages_HDR_Retina_toneMapping.cpp @@ -16,289 +16,290 @@ static void help(std::string errorMessage) { - std::cout<<"Program init error : "<(i))), - cv::Scalar::all(0), -1, 8, 0 ); - rectangle( displayedCurveImage, cv::Point(0, 0), - cv::Point((lowerLimit)*binW, 200), - cv::Scalar::all(128), -1, 8, 0 ); - rectangle( displayedCurveImage, cv::Point(displayedCurveImage.cols, 0), - cv::Point((upperLimit)*binW, 200), - cv::Scalar::all(128), -1, 8, 0 ); - - cv::imshow(figureTitle, displayedCurveImage); + //std::cout<<"curve size(h,w) = "<(i))), + cv::Scalar::all(0), -1, 8, 0 ); + rectangle( displayedCurveImage, cv::Point(0, 0), + cv::Point((lowerLimit)*binW, 200), + cv::Scalar::all(128), -1, 8, 0 ); + rectangle( displayedCurveImage, cv::Point(displayedCurveImage.cols, 0), + cv::Point((upperLimit)*binW, 200), + cv::Scalar::all(128), -1, 8, 0 ); + + cv::imshow(figureTitle, displayedCurveImage); } /* * objective : get the gray level map of the input image and rescale it to the range [0-255] */ - static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, const float histogramClippingLimit) - { - - // adjust output matrix wrt the input size but single channel - std::cout<<"Input image rescaling with histogram edges cutting (in order to eliminate bad pixels created during the HDR image creation) :"< image size (h,w,channels) = "< pixel coding (nbchannel, bytes per channel) = "<(0)=normalizedHist.at(0); - int histLowerLimit=0, histUpperLimit=0; - for (int i=1;i(i)=denseProb.at(i-1)+normalizedHist.at(i); - //std::cout<(i)<<", "<(i)<(i)(i)<1-histogramClippingLimit) - histUpperLimit=i; - } - // deduce min and max admitted gray levels - float minInputValue = (float)histLowerLimit/histSize*255; - float maxInputValue = (float)histUpperLimit/histSize*255; - - std::cout<<"=> Histogram limits " - <<"\n\t"< normalizedHist value = "<(histLowerLimit)<<" => input gray level = "< normalizedHist value = "<(histUpperLimit)<<" => input gray level = "< the main application is tone mapping of HDR images (i.e. see on a 8bit display a more than 8bits coded (up to 16bits) image with details in high and low luminance ranges"< It applies a spectral whithening (mid-frequency details enhancement)"< high frequency spatio-temporal noise reduction"< low frequency luminance to be reduced (luminance range compression)"< local logarithmic luminance compression allows details to be enhanced in low light conditions\n"< reports comments/remarks at benoit.alexandre.vision@gmail.com"< more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"< 1. take a set of photos from the same viewpoint using bracketing ***"< 2. generate an OpenEXR image with tools like qtpfsgui.sourceforge.net ***"< 3. apply tone mapping with this program ***"< image size (h,w) = "<8bits linear rescaling ", inputImage); - imshow("EXR image with basic processing : 16bits=>8bits with gamma correction", gammaTransformedImage); - if (inputImage.empty()) - { - help("Input image could not be loaded, aborting"); - return -1; - } - - ////////////////////////////////////////////////////////////////////////////// - // Program start in a try/catch safety context (Retina may throw errors) - try - { - /* create a retina instance with default parameters setup, uncomment the initialisation you wanna test - * -> if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) - */ - if (useLogSampling) - { - retina = cv::bioinspired::createRetina(inputImage.size(),true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0); - } - else// -> else allocate "classical" retina : - retina = cv::bioinspired::createRetina(inputImage.size()); - - // create a fast retina tone mapper (Meyla&al algorithm) - std::cout<<"Allocating fast tone mapper..."< fastToneMapper=createRetinaFastToneMapping(inputImage.size()); - std::cout<<"Fast tone mapper allocated"<write("RetinaDefaultParameters.xml"); - - // desactivate Magnocellular pathway processing (motion information extraction) since it is not usefull here - retina->activateMovingContoursProcessing(false); - - // declare retina output buffers - cv::Mat retinaOutput_parvo; - - ///////////////////////////////////////////// - // prepare displays and interactions - histogramClippingValue=0; // default value... updated with interface slider - //inputRescaleMat = inputImage; - //outputRescaleMat = imageInputRescaled; - cv::namedWindow("Processing configuration",1); - cv::createTrackbar("histogram edges clipping limit", "Processing configuration",&histogramClippingValue,50,callBack_rescaleGrayLevelMat); - - colorSaturationFactor=3; - cv::createTrackbar("Color saturation", "Processing configuration", &colorSaturationFactor,5,callback_saturateColors); - - retinaHcellsGain=40; - cv::createTrackbar("Hcells gain", "Processing configuration",&retinaHcellsGain,100,callBack_updateRetinaParams); - - localAdaptation_photoreceptors=197; - localAdaptation_Gcells=190; - cv::createTrackbar("Ph sensitivity", "Processing configuration", &localAdaptation_photoreceptors,199,callBack_updateRetinaParams); - cv::createTrackbar("Gcells sensitivity", "Processing configuration", &localAdaptation_Gcells,199,callBack_updateRetinaParams); - - - ///////////////////////////////////////////// - // apply default parameters of user interaction variables - rescaleGrayLevelMat(inputImage, imageInputRescaled, (float)histogramClippingValue/100); - retina->setColorSaturation(true,(float)colorSaturationFactor); - callBack_updateRetinaParams(1,NULL); // first call for default parameters setup - - // processing loop with stop condition - bool continueProcessing=true; - while(continueProcessing) - { - // run retina filter - if (!chosenMethod) - { - retina->run(imageInputRescaled); - // Retrieve and display retina output - retina->getParvo(retinaOutput_parvo); - cv::imshow("Retina input image (with cut edges histogram for basic pixels error avoidance)", imageInputRescaled/255.0); - cv::imshow("Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", retinaOutput_parvo); - cv::imwrite("HDRinput.jpg",imageInputRescaled/255.0); - cv::imwrite("RetinaToneMapping.jpg",retinaOutput_parvo); - } - else - { - // apply the simplified hdr tone mapping method - cv::Mat fastToneMappingOutput; - retina->applyFastToneMapping(imageInputRescaled, fastToneMappingOutput); - cv::imshow("Retina fast tone mapping output : 16bit=>8bit image retina tonemapping", fastToneMappingOutput); - } - /*cv::Mat fastToneMappingOutput_specificObject; +static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, const float histogramClippingLimit) +{ + + // adjust output matrix wrt the input size but single channel + std::cout<<"Input image rescaling with histogram edges cutting (in order to eliminate bad pixels created during the HDR image creation) :"< image size (h,w,channels) = "< pixel coding (nbchannel, bytes per channel) = "<(0)=normalizedHist.at(0); + int histLowerLimit=0, histUpperLimit=0; + for (int i=1;i(i)=denseProb.at(i-1)+normalizedHist.at(i); + //std::cout<(i)<<", "<(i)<(i)(i)<1-histogramClippingLimit) + histUpperLimit=i; + } + // deduce min and max admitted gray levels + float minInputValue = (float)histLowerLimit/histSize*255; + float maxInputValue = (float)histUpperLimit/histSize*255; + + std::cout<<"=> Histogram limits " + <<"\n\t"< normalizedHist value = "<(histLowerLimit)<<" => input gray level = "< normalizedHist value = "<(histUpperLimit)<<" => input gray level = "< the main application is tone mapping of HDR images (i.e. see on a 8bit display a more than 8bits coded (up to 16bits) image with details in high and low luminance ranges"< It applies a spectral whithening (mid-frequency details enhancement)"< high frequency spatio-temporal noise reduction"< low frequency luminance to be reduced (luminance range compression)"< local logarithmic luminance compression allows details to be enhanced in low light conditions\n"< reports comments/remarks at benoit.alexandre.vision@gmail.com"< more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"< 1. take a set of photos from the same viewpoint using bracketing ***"< 2. generate an OpenEXR image with tools like qtpfsgui.sourceforge.net ***"< 3. apply tone mapping with this program ***"< image size (h,w) = "<8bits linear rescaling ", inputImage); + imshow("EXR image with basic processing : 16bits=>8bits with gamma correction", gammaTransformedImage); + if (inputImage.empty()) + { + help("Input image could not be loaded, aborting"); + return -1; + } + + ////////////////////////////////////////////////////////////////////////////// + // Program start in a try/catch safety context (Retina may throw errors) + try + { + /* create a retina instance with default parameters setup, uncomment the initialisation you wanna test + * -> if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) + */ + if (useLogSampling) + { + retina = cv::bioinspired::createRetina(inputImage.size(),true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0); + } + else// -> else allocate "classical" retina : + retina = cv::bioinspired::createRetina(inputImage.size()); + + // create a fast retina tone mapper (Meyla&al algorithm) + std::cout<<"Allocating fast tone mapper..."< fastToneMapper=createRetinaFastToneMapping(inputImage.size()); + std::cout<<"Fast tone mapper allocated"<write("RetinaDefaultParameters.xml"); + + // desactivate Magnocellular pathway processing (motion information extraction) since it is not usefull here + retina->activateMovingContoursProcessing(false); + + // declare retina output buffers + cv::Mat retinaOutput_parvo; + + ///////////////////////////////////////////// + // prepare displays and interactions + histogramClippingValue=0; // default value... updated with interface slider + //inputRescaleMat = inputImage; + //outputRescaleMat = imageInputRescaled; + cv::namedWindow("Processing configuration",1); + cv::createTrackbar("histogram edges clipping limit", "Processing configuration",&histogramClippingValue,50,callBack_rescaleGrayLevelMat); + + colorSaturationFactor=3; + cv::createTrackbar("Color saturation", "Processing configuration", &colorSaturationFactor,5,callback_saturateColors); + + retinaHcellsGain=40; + cv::createTrackbar("Hcells gain", "Processing configuration",&retinaHcellsGain,100,callBack_updateRetinaParams); + + localAdaptation_photoreceptors=197; + localAdaptation_Gcells=190; + cv::createTrackbar("Ph sensitivity", "Processing configuration", &localAdaptation_photoreceptors,199,callBack_updateRetinaParams); + cv::createTrackbar("Gcells sensitivity", "Processing configuration", &localAdaptation_Gcells,199,callBack_updateRetinaParams); + + + ///////////////////////////////////////////// + // apply default parameters of user interaction variables + rescaleGrayLevelMat(inputImage, imageInputRescaled, (float)histogramClippingValue/100); + retina->setColorSaturation(true,(float)colorSaturationFactor); + callBack_updateRetinaParams(1,NULL); // first call for default parameters setup + + // processing loop with stop condition + bool continueProcessing=true; + while(continueProcessing) + { + // run retina filter + if (!chosenMethod) + { + retina->run(imageInputRescaled); + // Retrieve and display retina output + retina->getParvo(retinaOutput_parvo); + cv::imshow("Retina input image (with cut edges histogram for basic pixels error avoidance)", imageInputRescaled/255.0); + cv::imshow("Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", retinaOutput_parvo); + cv::imwrite("HDRinput.jpg",imageInputRescaled/255.0); + cv::imwrite("RetinaToneMapping.jpg",retinaOutput_parvo); + } + else + { + // apply the simplified hdr tone mapping method + cv::Mat fastToneMappingOutput; + retina->applyFastToneMapping(imageInputRescaled, fastToneMappingOutput); + cv::imshow("Retina fast tone mapping output : 16bit=>8bit image retina tonemapping", fastToneMappingOutput); + } + /*cv::Mat fastToneMappingOutput_specificObject; fastToneMapper->setup(3.f, 1.5f, 1.f); fastToneMapper->applyFastToneMapping(imageInputRescaled, fastToneMappingOutput_specificObject); cv::imshow("### Retina fast tone mapping output : 16bit=>8bit image retina tonemapping", fastToneMappingOutput_specificObject); -*/ - cv::waitKey(10); - } - }catch(cv::Exception e) - { - std::cerr<<"Error using Retina : "< It applies a spectral whithening (mid-frequency details enhancement)"< high frequency spatio-temporal noise reduction"< low frequency luminance to be reduced (luminance range compression)"< local logarithmic luminance compression allows details to be enhanced in low light conditions\n"< reports comments/remarks at benoit.alexandre.vision@gmail.com"< more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"< you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<= 3) - { - std::cout<<"RetinaDemo: processing image "<>inputFrame; - }else - { - // bad command parameter - help("bad command parameter"); - return -1; - } - - if (inputFrame.empty()) - { - help("Input media could not be loaded, aborting"); - return -1; - } - - - ////////////////////////////////////////////////////////////////////////////// - // Program start in a try/catch safety context (Retina may throw errors) - try - { - // create a retina instance with default parameters setup, uncomment the initialisation you wanna test - cv::Ptr myRetina; - - // if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) - if (useLogSampling) - { - myRetina = cv::bioinspired::createRetina(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0); - } - else// -> else allocate "classical" retina : - myRetina = cv::bioinspired::createRetina(inputFrame.size()); - - // save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup" - myRetina->write("RetinaDefaultParameters.xml"); - - // load parameters if file exists - myRetina->setup("RetinaSpecificParameters.xml"); - myRetina->clearBuffers(); - - // declare retina output buffers - cv::Mat retinaOutput_parvo; - cv::Mat retinaOutput_magno; - - // processing loop with stop condition - bool continueProcessing=true; // FIXME : not yet managed during process... - while(continueProcessing) - { - // if using video stream, then, grabbing a new frame, else, input remains the same - if (videoCapture.isOpened()) - videoCapture>>inputFrame; - - // run retina filter - myRetina->run(inputFrame); - // Retrieve and display retina output - myRetina->getParvo(retinaOutput_parvo); - myRetina->getMagno(retinaOutput_magno); - cv::imshow("retina input", inputFrame); - cv::imshow("Retina Parvo", retinaOutput_parvo); - cv::imshow("Retina Magno", retinaOutput_magno); - - cv::waitKey(5); - } - }catch(cv::Exception e) - { - std::cerr<<"Error using Retina : "< It applies a spectral whithening (mid-frequency details enhancement)"< high frequency spatio-temporal noise reduction"< low frequency luminance to be reduced (luminance range compression)"< local logarithmic luminance compression allows details to be enhanced in low light conditions\n"< reports comments/remarks at benoit.alexandre.vision@gmail.com"< more informations and papers at : http://sites.google.com/site/benoitalexandrevision/"< you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<= 3) + { + std::cout<<"RetinaDemo: processing image "<>inputFrame; + }else + { + // bad command parameter + help("bad command parameter"); + return -1; + } + + if (inputFrame.empty()) + { + help("Input media could not be loaded, aborting"); + return -1; + } + + + ////////////////////////////////////////////////////////////////////////////// + // Program start in a try/catch safety context (Retina may throw errors) + try + { + // create a retina instance with default parameters setup, uncomment the initialisation you wanna test + cv::Ptr myRetina; + + // if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) + if (useLogSampling) + { + myRetina = cv::bioinspired::createRetina(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0); + } + else// -> else allocate "classical" retina : + myRetina = cv::bioinspired::createRetina(inputFrame.size()); + + // save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup" + myRetina->write("RetinaDefaultParameters.xml"); + + // load parameters if file exists + myRetina->setup("RetinaSpecificParameters.xml"); + myRetina->clearBuffers(); + + // declare retina output buffers + cv::Mat retinaOutput_parvo; + cv::Mat retinaOutput_magno; + + // processing loop with stop condition + bool continueProcessing=true; // FIXME : not yet managed during process... + while(continueProcessing) + { + // if using video stream, then, grabbing a new frame, else, input remains the same + if (videoCapture.isOpened()) + videoCapture>>inputFrame; + + // run retina filter + myRetina->run(inputFrame); + // Retrieve and display retina output + myRetina->getParvo(retinaOutput_parvo); + myRetina->getMagno(retinaOutput_magno); + cv::imshow("retina input", inputFrame); + cv::imshow("Retina Parvo", retinaOutput_parvo); + cv::imshow("Retina Magno", retinaOutput_magno); + + cv::waitKey(5); + } + }catch(cv::Exception e) + { + std::cerr<<"Error using Retina : "<