From 6395a738cb57220fcdf89a37335ff80a22b646f9 Mon Sep 17 00:00:00 2001 From: Alexandre Benoit Date: Sat, 13 Aug 2011 14:19:17 +0000 Subject: [PATCH] adding openexr images tone mapping demo --- ...es_HighDynamicRange_Retina_toneMapping.cpp | 266 ++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp diff --git a/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp new file mode 100644 index 000000000..0eb4e0af2 --- /dev/null +++ b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp @@ -0,0 +1,266 @@ + +//============================================================================ +// Name : HighDynamicRange_RetinaCompression.cpp +// Author : Alexandre Benoit (benoit.alexandre.vision@gmail.com) +// Version : 0.1 +// Copyright : Alexandre Benoit, LISTIC Lab, july 2011 +// Description : HighDynamicRange compression (tone mapping) with the help of the Gipsa/Listic's retina in C++, Ansi-style +//============================================================================ + +#include +#include + +#include "opencv2/opencv.hpp" + +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); +} +/* + * objective : get the gray level map of the input image and rescale it to the range [0-255] + */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..."< 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"< 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 >8bit (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"< 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 ***"< if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision) + */ + if (useLogSampling) + retina = new cv::Retina("params.xml", inputImage.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0); + else// -> else allocate "classical" retina : + retina = new cv::Retina("params.xml", inputImage.size()); + + // declare retina output buffers + cv::Mat retinaOutput_parvo; + cv::Mat retinaOutput_magno; + + ///////////////////////////////////////////// + // prepare displays and interactions + histogramClippingValue=0; // default value... updated with interface slider + //inputRescaleMat = inputImage; + //outputRescaleMat = imageInputRescaled; + cv::namedWindow("Cut histogram edges input image",1); + cv::createTrackbar("histogram edges clipping limit", "Cut histogram edges input image",&histogramClippingValue,50,callBack_rescaleGrayLevelMat); + + cv::namedWindow("Retina Parvo", 1); + colorSaturationFactor=2; + cv::createTrackbar("Color saturation", "Retina Parvo", &colorSaturationFactor,100,callback_saturateColors); + + retinaHcellsGain=40; + cv::createTrackbar("Retina horizontal cells gain", "Retina Parvo",&retinaHcellsGain,100,callBack_updateRetinaParams); + + localAdaptation_photoreceptors=99; + localAdaptation_Gcells=99; + cv::createTrackbar("Ph sensitivity", "Retina Parvo", &localAdaptation_photoreceptors,99,callBack_updateRetinaParams); + cv::createTrackbar("Gcells sensitivity", "Retina Parvo", &localAdaptation_Gcells,99,callBack_updateRetinaParams); + + ///////////////////////////////////////////// + // apply default parameters of user interaction variables + rescaleGrayLevelMat(inputImage, imageInputRescaled, (float)histogramClippingValue/100); + retina->setColorSaturation(true,colorSaturationFactor); + callBack_updateRetinaParams(1,NULL); // first call for default parameters setup + + // processing loop with stop condition + bool continueProcessing=true; + while(continueProcessing) + { + // run retina filter + retina->run(imageInputRescaled); + // Retrieve and display retina output + retina->getParvo(retinaOutput_parvo); + retina->getMagno(retinaOutput_magno); + cv::imshow("Cut histogram edges input image", imageInputRescaled/255.0); + cv::imshow("Retina Parvo", retinaOutput_parvo); + //cv::imshow("Retina Magno", retinaOutput_magno); // not usefull in this demo, uncomment if needed + cv::waitKey(10); + } + }catch(cv::Exception e) + { + std::cerr<<"Error using Retina : "<