“Fast Bilateral Filtering for the Display of High-Dynamic-Range Images” 论文实现

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;

class HDRCompressor
{
private:
Mat logRadianceMap;
Mat logBaseLayer;
Mat logDetailLayer;
Mat logOutIntensity;
Mat outIntensity;
public:
HDRCompressor(const Mat & p_lnRadianceMap);
void buildDetailBaseLayer();
void buildToneMappedPic();
};

#include "HDRCompressor.h"

using namespace std;
using namespace cv;

void powMat(const Mat & src,Mat & dst)
{
src.convertTo(src,CV_32FC1);
dst.create(src.rows,src.cols,CV_8UC1);
for (int i = 0;i < src.rows;i ++)
{
for (int j = 0;j < src.cols;j ++)
{
dst.at<uchar>(i,j) = saturate_cast<uchar>(pow(10,src.at<float>(i,j)));
}
}
}
double log_10(double x)
{
return log(x) / log(10.0);
}

HDRCompressor::HDRCompressor(const Mat & p_lnRadianceMap)
{
logRadianceMap = p_lnRadianceMap / log(10.0);
}

void HDRCompressor::buildDetailBaseLayer()
{
logRadianceMap.convertTo(logRadianceMap,CV_32FC1,1,0);
bilateralFilter(logRadianceMap,logBaseLayer,5,20,30);
logDetailLayer = logRadianceMap - logBaseLayer;

imshow("detail",logDetailLayer);
waitKey(5000);
}

void HDRCompressor::buildToneMappedPic()
{
buildDetailBaseLayer();

double minVal,maxVal,compressorFactor,absoluteScale;
minMaxLoc(logBaseLayer,&minVal,&maxVal,0,0);

compressorFactor = log_10(20) / (maxVal - minVal);

cout << "maxVal" << maxVal << ",compress:" << compressorFactor << endl;
absoluteScale = maxVal * compressorFactor / 50;

logOutIntensity.create(logRadianceMap.rows,logRadianceMap.cols,CV_64FC1);
logOutIntensity = logBaseLayer * compressorFactor + logDetailLayer - log_10(absoluteScale);

double minval,maxval;

minMaxLoc(logOutIntensity,&minval,&maxval,0,0);
cout << "yes" << minval << "," << maxval << endl;
//pow(logOutIntensity,10,outIntensity);
//logOutIntensity.convertTo(logOutIntensity,CV_8UC1);
powMat(logOutIntensity,outIntensity);
//convertScaleAbs(logOutIntensity,outIntensity,1,0);
imshow("outIntensity",outIntensity);
waitKey(100000);
}

posted @ 2013-07-12 22:29  lycv_wcc  阅读(813)  评论(0)    收藏  举报