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