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

pull/4018/head
Vadim Pisarevsky 10 years ago
parent ffabbfa778
commit 3c7f7de477
  1. 14
      modules/photo/src/tonemap.cpp

@ -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);

Loading…
Cancel
Save