From 9b6d3ef6588e59cb7392097353224de698d16697 Mon Sep 17 00:00:00 2001 From: Kari Pikkarainen Date: Fri, 20 Nov 2026 10:11:12 -0800 Subject: [PATCH] photo: compare MergeRobertson results relative to each pixel's brightness Photo_MergeRobertson.regression compared radiance values from 0.014 to 688 with one absolute limit of 6 (raised from 5 for AArch64 in 2017, then for all platforms). The result measured 5.84 on Linux and macOS ARM64 and 3.92 on Linux and Windows x64, while an error in dark pixels could not fail the test at all. Radiance (.hdr) files store each pixel with one shared exponent, so each channel is only as precise as the pixel's brightest channel allows. The new check scales the error by that channel. The result measures 0.91% on ARM64 and 0.78% on x64; the limit is 1.5%. Non-finite values fail the check before it reduces the differences with minMaxLoc(). Checked against modified results on macOS ARM64: dark pixels doubled (102%) and the brightest exposure dropped (288%) passed the old check and fail now; all exposure times 2% off still fails (1.96%). Prepared with AI assistance (Claude Code); I reviewed the change and the verification results. Co-Authored-By: Claude Opus 5.5 --- modules/photo/test/test_hdr.cpp | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/modules/photo/test/test_hdr.cpp b/modules/photo/test/test_hdr.cpp index 2d3f259937..23cdf52118 100644 --- a/modules/photo/test/test_hdr.cpp +++ b/modules/photo/test/test_hdr.cpp @@ -56,6 +56,38 @@ void checkEqual(Mat img0, Mat img1, double threshold, const string& name) ASSERT_FALSE(max > threshold) << "max=" << max << " threshold=" << threshold << " method=" << name; } +// Radiance .hdr files store three mantissas with one shared exponent, so each +// channel is stored to a precision proportional to the pixel's brightest channel. +// Compare against that scale instead of one absolute threshold for the whole image. +void checkEqualRelativeToPixelMax(const Mat& expected, const Mat& actual, double threshold, const string& name) +{ + ASSERT_EQ(CV_32FC3, expected.type()); + ASSERT_EQ(expected.type(), actual.type()); + ASSERT_EQ(expected.size(), actual.size()); + // minMaxLoc() below may skip NaN, so reject non-finite values first. + ASSERT_TRUE(cv::checkRange(expected)) << "non-finite values in the expected image, method=" << name; + ASSERT_TRUE(cv::checkRange(actual)) << "non-finite values in the actual image, method=" << name; + std::vector channels; + cv::split(expected, channels); + Mat scale; + cv::max(channels[0], channels[1], scale); + cv::max(scale, channels[2], scale); + double min_scale = 0; + cv::minMaxLoc(scale, &min_scale); + ASSERT_GT(min_scale, 0) << "method=" << name; + std::vector diff; + cv::split(abs(expected - actual), diff); + Mat worst; + cv::max(diff[0], diff[1], worst); + cv::max(worst, diff[2], worst); + cv::divide(worst, scale, worst); + double max_rel = 0; + Point where; + cv::minMaxLoc(worst, NULL, &max_rel, NULL, &where); + ASSERT_LE(max_rel, threshold) << "method=" << name << " at " << where + << " expected=" << expected.at(where) << " actual=" << actual.at(where); +} + static vector DEFAULT_VECTOR; void loadExposureSeq(String path, vector& images, vector& times = DEFAULT_VECTOR) { @@ -226,8 +258,7 @@ TEST(Photo_MergeRobertson, regression) loadImage(test_path + "merge/robertson.hdr", expected); merge->process(images, result, times); - const float eps = 6.f; - checkEqual(expected, result, eps, "MergeRobertson"); + checkEqualRelativeToPixelMax(expected, result, 0.015, "MergeRobertson"); } TEST(Photo_MergeDebevec, regression_depth_consistency)