test_hdr.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. using namespace cv::xphoto;
  7. #ifdef OPENCV_ENABLE_NONFREE
  8. void loadImage(string path, Mat &img)
  9. {
  10. img = imread(path, -1);
  11. ASSERT_FALSE(img.empty()) << "Could not load input image " << path;
  12. }
  13. void checkEqual(Mat img0, Mat img1, double threshold, const string& name)
  14. {
  15. double max = 1.0;
  16. minMaxLoc(abs(img0 - img1), NULL, &max);
  17. ASSERT_FALSE(max > threshold) << "max=" << max << " threshold=" << threshold << " method=" << name;
  18. }
  19. TEST(Photo_Tonemap, Durand_regression)
  20. {
  21. string test_path = string(cvtest::TS::ptr()->get_data_path()) + "cv/hdr/tonemap/";
  22. Mat img, expected, result;
  23. loadImage(test_path + "image.hdr", img);
  24. float gamma = 2.2f;
  25. Ptr<TonemapDurand> durand = createTonemapDurand(gamma);
  26. durand->process(img, result);
  27. loadImage(test_path + "durand.png", expected);
  28. result.convertTo(result, CV_8UC3, 255);
  29. checkEqual(result, expected, 3, "Durand");
  30. }
  31. TEST(Photo_Tonemap, Durand_property_regression)
  32. {
  33. const float gamma = 1.0f;
  34. const float contrast = 2.0f;
  35. const float saturation = 3.0f;
  36. const float sigma_color = 4.0f;
  37. const float sigma_space = 5.0f;
  38. const Ptr<TonemapDurand> durand1 = createTonemapDurand(gamma, contrast, saturation, sigma_color, sigma_space);
  39. ASSERT_EQ(gamma, durand1->getGamma());
  40. ASSERT_EQ(contrast, durand1->getContrast());
  41. ASSERT_EQ(saturation, durand1->getSaturation());
  42. ASSERT_EQ(sigma_space, durand1->getSigmaSpace());
  43. ASSERT_EQ(sigma_color, durand1->getSigmaColor());
  44. const Ptr<TonemapDurand> durand2 = createTonemapDurand();
  45. durand2->setGamma(gamma);
  46. durand2->setContrast(contrast);
  47. durand2->setSaturation(saturation);
  48. durand2->setSigmaColor(sigma_color);
  49. durand2->setSigmaSpace(sigma_space);
  50. ASSERT_EQ(gamma, durand2->getGamma());
  51. ASSERT_EQ(contrast, durand2->getContrast());
  52. ASSERT_EQ(saturation, durand2->getSaturation());
  53. ASSERT_EQ(sigma_color, durand2->getSigmaColor());
  54. ASSERT_EQ(sigma_space, durand2->getSigmaSpace());
  55. }
  56. #endif // OPENCV_ENABLE_NONFREE
  57. }} // namespace