avoid possible problems with zero values in tone mapping algorithms (http://code.opencv.org/issues/4020)

This commit is contained in:
Vadim Pisarevsky 2015-05-14 19:32:25 +03:00
parent ffabbfa778
commit 3c7f7de477

View File

@ -47,6 +47,12 @@
namespace cv
{
inline void log_(const Mat& src, Mat& dst)
{
max(src, Scalar::all(1e-4), dst);
log(dst, dst);
}
class TonemapImpl : public Tonemap
{
public:
@ -122,7 +128,7 @@ public:
Mat gray_img;
cvtColor(img, gray_img, COLOR_RGB2GRAY);
Mat log_img;
log(gray_img, log_img);
log_(gray_img, log_img);
float mean = expf(static_cast<float>(sum(log_img)[0]) / log_img.total());
gray_img /= mean;
log_img.release();
@ -205,7 +211,7 @@ public:
Mat gray_img;
cvtColor(img, gray_img, COLOR_RGB2GRAY);
Mat log_img;
log(gray_img, log_img);
log_(gray_img, log_img);
Mat map_img;
bilateralFilter(log_img, map_img, -1, sigma_color, sigma_space);
@ -289,7 +295,7 @@ public:
Mat gray_img;
cvtColor(img, gray_img, COLOR_RGB2GRAY);
Mat log_img;
log(gray_img, log_img);
log_(gray_img, log_img);
float log_mean = static_cast<float>(sum(log_img)[0] / log_img.total());
double log_min, log_max;
@ -383,7 +389,7 @@ public:
Mat gray_img;
cvtColor(img, gray_img, COLOR_RGB2GRAY);
Mat log_img;
log(gray_img, log_img);
log_(gray_img, log_img);
std::vector<Mat> x_contrast, y_contrast;
getContrast(log_img, x_contrast, y_contrast);