test_ccm.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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
  6. {
  7. namespace
  8. {
  9. Mat s = (Mat_<Vec3d>(24, 1) <<
  10. Vec3d(214.11, 98.67, 37.97),
  11. Vec3d(231.94, 153.1, 85.27),
  12. Vec3d(204.08, 143.71, 78.46),
  13. Vec3d(190.58, 122.99, 30.84),
  14. Vec3d(230.93, 148.46, 100.84),
  15. Vec3d(228.64, 206.97, 97.5),
  16. Vec3d(229.09, 137.07, 55.29),
  17. Vec3d(189.21, 111.22, 92.66),
  18. Vec3d(223.5, 96.42, 75.45),
  19. Vec3d(201.82, 69.71, 50.9),
  20. Vec3d(240.52, 196.47, 59.3),
  21. Vec3d(235.73, 172.13, 54.),
  22. Vec3d(131.6, 75.04, 68.86),
  23. Vec3d(189.04, 170.43, 42.05),
  24. Vec3d(222.23, 74., 71.95),
  25. Vec3d(241.01, 199.1, 61.15),
  26. Vec3d(224.99, 101.4, 100.24),
  27. Vec3d(174.58, 152.63, 91.52),
  28. Vec3d(248.06, 227.69, 140.5),
  29. Vec3d(241.15, 201.38, 115.58),
  30. Vec3d(236.49, 175.87, 88.86),
  31. Vec3d(212.19, 133.49, 54.79),
  32. Vec3d(181.17, 102.94, 36.18),
  33. Vec3d(115.1, 53.77, 15.23));
  34. TEST(CV_ccmRunColorCorrection, test_model)
  35. {
  36. ColorCorrectionModel model(s / 255, COLORCHECKER_Macbeth);
  37. model.run();
  38. Mat src_rgbl = (Mat_<Vec3d>(24, 1) <<
  39. Vec3d(0.68078957, 0.12382801, 0.01514889),
  40. Vec3d(0.81177942, 0.32550452, 0.089818),
  41. Vec3d(0.61259378, 0.2831933, 0.07478902),
  42. Vec3d(0.52696493, 0.20105976, 0.00958657),
  43. Vec3d(0.80402284, 0.30419523, 0.12989841),
  44. Vec3d(0.78658646, 0.63184111, 0.12062068),
  45. Vec3d(0.78999637, 0.25520249, 0.03462853),
  46. Vec3d(0.51866697, 0.16114393, 0.1078387),
  47. Vec3d(0.74820768, 0.11770076, 0.06862177),
  48. Vec3d(0.59776825, 0.05765816, 0.02886627),
  49. Vec3d(0.8793145, 0.56346033, 0.0403954),
  50. Vec3d(0.84124847, 0.42120746, 0.03287592),
  51. Vec3d(0.23333214, 0.06780408, 0.05612276),
  52. Vec3d(0.5176423, 0.41210976, 0.01896255),
  53. Vec3d(0.73888613, 0.06575388, 0.06181293),
  54. Vec3d(0.88326036, 0.58018751, 0.04321991),
  55. Vec3d(0.75922531, 0.13149072, 0.1282041),
  56. Vec3d(0.4345097, 0.32331019, 0.10494139),
  57. Vec3d(0.94110142, 0.77941419, 0.26946323),
  58. Vec3d(0.88438952, 0.5949049 , 0.17536928),
  59. Vec3d(0.84722687, 0.44160449, 0.09834799),
  60. Vec3d(0.66743106, 0.24076803, 0.03394333),
  61. Vec3d(0.47141286, 0.13592419, 0.01362205),
  62. Vec3d(0.17377101, 0.03256864, 0.00203026));
  63. ASSERT_MAT_NEAR(src_rgbl, model.get_src_rgbl(), 1e-4);
  64. Mat dst_rgbl = (Mat_<Vec3d>(24, 1) <<
  65. Vec3d(0.17303173, 0.08211037, 0.05672686),
  66. Vec3d(0.56832031, 0.29269488, 0.21835529),
  67. Vec3d(0.10365019, 0.19588357, 0.33140475),
  68. Vec3d(0.10159676, 0.14892193, 0.05188294),
  69. Vec3d(0.22159627, 0.21584476, 0.43461196),
  70. Vec3d(0.10806379, 0.51437196, 0.41264213),
  71. Vec3d(0.74736423, 0.20062878, 0.02807988),
  72. Vec3d(0.05757947, 0.10516793, 0.40296109),
  73. Vec3d(0.56676218, 0.08424805, 0.11969461),
  74. Vec3d(0.11099515, 0.04230796, 0.14292554),
  75. Vec3d(0.34546869, 0.50872001, 0.04944204),
  76. Vec3d(0.79461323, 0.35942459, 0.02051968),
  77. Vec3d(0.01710416, 0.05022043, 0.29220674),
  78. Vec3d(0.05598012, 0.30021149, 0.06871162),
  79. Vec3d(0.45585457, 0.03033727, 0.04085654),
  80. Vec3d(0.85737614, 0.56757335, 0.0068503),
  81. Vec3d(0.53348585, 0.08861148, 0.30750446),
  82. Vec3d(-0.0374061, 0.24699498, 0.40041217),
  83. Vec3d(0.91262695, 0.91493909, 0.89367049),
  84. Vec3d(0.57981916, 0.59200418, 0.59328881),
  85. Vec3d(0.35490581, 0.36544831, 0.36755375),
  86. Vec3d(0.19007357, 0.19186587, 0.19308397),
  87. Vec3d(0.08529188, 0.08887994, 0.09257601),
  88. Vec3d(0.0303193, 0.03113818, 0.03274845));
  89. ASSERT_MAT_NEAR(dst_rgbl, model.get_dst_rgbl(), 1e-4);
  90. Mat mask = Mat::ones(24, 1, CV_8U);
  91. ASSERT_MAT_NEAR(model.getMask(), mask, 0.0);
  92. Mat ccm = (Mat_<double>(3, 3) <<
  93. 0.37406520, 0.02066507, 0.05804047,
  94. 0.12719672, 0.77389268, -0.01569404,
  95. -0.27627010, 0.00603427, 2.74272981);
  96. ASSERT_MAT_NEAR(model.getCCM(), ccm, 1e-4);
  97. }
  98. TEST(CV_ccmRunColorCorrection, test_masks_weights_1)
  99. {
  100. Mat weights_list_ = (Mat_<double>(24, 1) <<
  101. 1.1, 0, 0, 1.2, 0, 0,
  102. 1.3, 0, 0, 1.4, 0, 0,
  103. 0.5, 0, 0, 0.6, 0, 0,
  104. 0.7, 0, 0, 0.8, 0, 0);
  105. ColorCorrectionModel model1(s / 255,COLORCHECKER_Macbeth);
  106. model1.setColorSpace(COLOR_SPACE_sRGB);
  107. model1.setCCM_TYPE(CCM_3x3);
  108. model1.setDistance(DISTANCE_CIE2000);
  109. model1.setLinear(LINEARIZATION_GAMMA);
  110. model1.setLinearGamma(2.2);
  111. model1.setLinearDegree(3);
  112. model1.setSaturatedThreshold(0, 0.98);
  113. model1.setWeightsList(weights_list_);
  114. model1.setWeightCoeff(1.5);
  115. model1.run();
  116. Mat weights = (Mat_<double>(8, 1) <<
  117. 1.15789474, 1.26315789, 1.36842105, 1.47368421,
  118. 0.52631579, 0.63157895, 0.73684211, 0.84210526);
  119. ASSERT_MAT_NEAR(model1.getWeights(), weights, 1e-4);
  120. Mat mask = (Mat_<uchar>(24, 1) <<
  121. true, false, false, true, false, false,
  122. true, false, false, true, false, false,
  123. true, false, false, true, false, false,
  124. true, false, false, true, false, false);
  125. ASSERT_MAT_NEAR(model1.getMask(), mask, 0.0);
  126. }
  127. TEST(CV_ccmRunColorCorrection, test_masks_weights_2)
  128. {
  129. ColorCorrectionModel model2(s / 255, COLORCHECKER_Macbeth);
  130. model2.setCCM_TYPE(CCM_3x3);
  131. model2.setDistance(DISTANCE_CIE2000);
  132. model2.setLinear(LINEARIZATION_GAMMA);
  133. model2.setLinearGamma(2.2);
  134. model2.setLinearDegree(3);
  135. model2.setSaturatedThreshold(0.05, 0.93);
  136. model2.setWeightsList(Mat());
  137. model2.setWeightCoeff(1.5);
  138. model2.run();
  139. Mat weights = (Mat_<double>(20, 1) <<
  140. 0.65554256, 1.49454705, 1.00499244, 0.79735434, 1.16327759,
  141. 1.68623868, 1.37973155, 0.73213388, 1.0169629, 0.47430246,
  142. 1.70312161, 0.45414218, 1.15910007, 0.7540434, 1.05049802,
  143. 1.04551645, 1.54082353, 1.02453421, 0.6015915, 0.26154558);
  144. ASSERT_MAT_NEAR(model2.getWeights(), weights, 1e-4);
  145. Mat mask = (Mat_<uchar>(24, 1) <<
  146. true, true, true, true, true, true,
  147. true, true, true, true, false, true,
  148. true, true, true, false, true, true,
  149. false, false, true, true, true, true);
  150. ASSERT_MAT_NEAR(model2.getMask(), mask, 0.0);
  151. }
  152. } // namespace
  153. } // namespace opencv_test