diff --git a/doc/tutorials/others/images/ldr.png b/doc/tutorials/others/images/ldr.png index 2e1a188e6b..ac420886fa 100644 Binary files a/doc/tutorials/others/images/ldr.png and b/doc/tutorials/others/images/ldr.png differ diff --git a/modules/photo/src/hdr_common.cpp b/modules/photo/src/hdr_common.cpp index 5e4bea9d85..70b24322b1 100644 --- a/modules/photo/src/hdr_common.cpp +++ b/modules/photo/src/hdr_common.cpp @@ -65,10 +65,14 @@ Mat triangleWeights() Mat w(LDR_SIZE, 1, CV_32F); int half = LDR_SIZE / 2; int maxVal = LDR_SIZE - 1; - for (int i = 0; i < LDR_SIZE; i++) + float epsilon = 1e-6f; + w.at(0) = epsilon; + w.at(LDR_SIZE-1) = epsilon; + for (int i = 1; i < LDR_SIZE-1; i++){ w.at(i) = (i < half) ? static_cast(i) : static_cast(maxVal - i); + } return w; } diff --git a/modules/photo/src/tonemap.cpp b/modules/photo/src/tonemap.cpp index 0c9275040b..6f90c76b20 100644 --- a/modules/photo/src/tonemap.cpp +++ b/modules/photo/src/tonemap.cpp @@ -72,8 +72,10 @@ public: double min, max; minMaxLoc(src, &min, &max); + float fmin = static_cast(min); + float fmax = static_cast(max); if(max - min > DBL_EPSILON) { - dst = (src - min) / (max - min); + dst = (src - fmin) / (fmax - fmin); } else { src.copyTo(dst); } @@ -139,8 +141,9 @@ public: gray_img /= mean; log_img.release(); - double max; - minMaxLoc(gray_img, NULL, &max); + double dmax; + minMaxLoc(gray_img, NULL, &dmax); + float max = static_cast(dmax); CV_Assert(max > 0); Mat map; @@ -150,7 +153,6 @@ public: log(2.0f + 8.0f * div, div); map = map.mul(1.0f / div); div.release(); - mapLuminance(img, img, gray_img, map, saturation); linear->setGamma(gamma); @@ -223,12 +225,14 @@ public: log_(gray_img, log_img); float log_mean = static_cast(sum(log_img)[0] / log_img.total()); - double log_min, log_max; - minMaxLoc(log_img, &log_min, &log_max); + double dlog_min, dlog_max; + minMaxLoc(log_img, &dlog_min, &dlog_max); + float log_max = static_cast(dlog_max); + float log_min = static_cast(dlog_min); log_img.release(); - double key = static_cast((log_max - log_mean) / (log_max - log_min)); - float map_key = 0.3f + 0.7f * pow(static_cast(key), 1.4f); + float key = (log_max - log_mean) / (log_max - log_min); + float map_key = 0.3f + 0.7f * pow(key, 1.4f); intensity = exp(-intensity); Scalar chan_mean = mean(img); float gray_mean = static_cast(mean(gray_img)[0]); @@ -287,9 +291,9 @@ protected: float gamma, intensity, light_adapt, color_adapt; }; -Ptr createTonemapReinhard(float gamma, float contrast, float sigma_color, float sigma_space) +Ptr createTonemapReinhard(float gamma, float intensity, float light_adapt, float color_adapt) { - return makePtr(gamma, contrast, sigma_color, sigma_space); + return makePtr(gamma, intensity, light_adapt, color_adapt); } class TonemapMantiukImpl CV_FINAL : public TonemapMantiuk diff --git a/samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp b/samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp index 5e8843bcf0..83711d5949 100644 --- a/samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp +++ b/samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp @@ -35,7 +35,7 @@ int main(int argc, char**argv) //! [Tonemap HDR image] Mat ldr; - Ptr tonemap = createTonemap(2.2f); + Ptr tonemap = createTonemapDrago(2.2f); tonemap->process(hdr, ldr); //! [Tonemap HDR image] diff --git a/samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py b/samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py index a5403d3cca..6ab7cf1a0a 100644 --- a/samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py +++ b/samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py @@ -40,7 +40,7 @@ hdr = merge_debevec.process(images, times, response) ## [Make HDR image] ## [Tonemap HDR image] -tonemap = cv.createTonemap(2.2) +tonemap = cv.createTonemapDrago(2.2) ldr = tonemap.process(hdr) ## [Tonemap HDR image]