diff --git a/modules/photo/src/tonemap.cpp b/modules/photo/src/tonemap.cpp index af930abb3..e475482d6 100644 --- a/modules/photo/src/tonemap.cpp +++ b/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(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(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 x_contrast, y_contrast; getContrast(log_img, x_contrast, y_contrast);