diff --git a/modules/cudaimgproc/test/test_color.cpp b/modules/cudaimgproc/test/test_color.cpp index e4f91ea1bc..3362fe5faf 100644 --- a/modules/cudaimgproc/test/test_color.cpp +++ b/modules/cudaimgproc/test/test_color.cpp @@ -1740,7 +1740,7 @@ CUDA_TEST_P(CvtColor, Lab2BGR) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2BGR); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, Lab2RGB) @@ -1757,7 +1757,7 @@ CUDA_TEST_P(CvtColor, Lab2RGB) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2RGB); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, Lab2BGRA) @@ -1776,7 +1776,7 @@ CUDA_TEST_P(CvtColor, Lab2BGRA) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2BGR, 4); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, Lab2LBGR) @@ -1793,7 +1793,7 @@ CUDA_TEST_P(CvtColor, Lab2LBGR) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2LBGR); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, Lab2LRGB) @@ -1810,7 +1810,7 @@ CUDA_TEST_P(CvtColor, Lab2LRGB) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2LRGB); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, Lab2LRGBA) @@ -1827,7 +1827,7 @@ CUDA_TEST_P(CvtColor, Lab2LRGBA) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Lab2LRGB, 4); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-5); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-5); } CUDA_TEST_P(CvtColor, BGR2Luv) @@ -1958,7 +1958,7 @@ CUDA_TEST_P(CvtColor, Luv2BGR) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Luv2BGR); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-4); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-4); } CUDA_TEST_P(CvtColor, Luv2RGB) @@ -1975,7 +1975,7 @@ CUDA_TEST_P(CvtColor, Luv2RGB) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Luv2RGB); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-4); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-4); } CUDA_TEST_P(CvtColor, Luv2BGRA) @@ -1994,7 +1994,7 @@ CUDA_TEST_P(CvtColor, Luv2BGRA) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Luv2BGR, 4); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-4); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-4); } CUDA_TEST_P(CvtColor, Luv2LBGR) @@ -2011,7 +2011,7 @@ CUDA_TEST_P(CvtColor, Luv2LBGR) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Luv2LBGR); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-4); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-4); } CUDA_TEST_P(CvtColor, Luv2LRGB) @@ -2028,7 +2028,7 @@ CUDA_TEST_P(CvtColor, Luv2LRGB) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_Luv2LRGB); - EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 1 : 1e-4); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_8U ? 2 : 1e-4); } CUDA_TEST_P(CvtColor, Luv2LRGBA) diff --git a/modules/cudev/include/opencv2/cudev/functional/detail/color_cvt.hpp b/modules/cudev/include/opencv2/cudev/functional/detail/color_cvt.hpp index a456dfad48..f485e09e5b 100644 --- a/modules/cudev/include/opencv2/cudev/functional/detail/color_cvt.hpp +++ b/modules/cudev/include/opencv2/cudev/functional/detail/color_cvt.hpp @@ -1207,27 +1207,29 @@ namespace color_cvt_detail __device__ typename MakeVec::type operator ()(const typename MakeVec::type& src) const { const float _d = 1.f / (0.950456f + 15 + 1.088754f * 3); - const float _un = 4 * 0.950456f * _d; - const float _vn = 9 * _d; + const float _un = 13 * 4 * 0.950456f * _d; + const float _vn = 13 * 9 * _d; float L = src.x; float u = src.y; float v = src.z; - float Y = (L + 16.f) * (1.f / 116.f); - Y = Y * Y * Y; + float Y1 = (L + 16.f) * (1.f / 116.f); + Y1 = Y1 * Y1 * Y1; + float Y0 = L * (1.f / 903.3f); + float Y = L <= 8.f ? Y0 : Y1; - float d = (1.f / 13.f) / L; - u = u * d + _un; - v = v * d + _vn; + u = (u + _un * L) * 3.f; + v = (v + _vn * L) * 4.f; float iv = 1.f / v; - float X = 2.25f * u * Y * iv; - float Z = (12 - 3 * u - 20 * v) * Y * 0.25f * iv; + iv = ::fmaxf(-0.25f, ::fminf(0.25f, iv)); + float X = 3.f * u * iv; + float Z = (12.f * 13.f * L - u) * iv - 5.f; - float B = 0.055648f * X - 0.204043f * Y + 1.057311f * Z; - float G = -0.969256f * X + 1.875991f * Y + 0.041556f * Z; - float R = 3.240479f * X - 1.537150f * Y - 0.498535f * Z; + float B = (0.055648f * X - 0.204043f + 1.057311f * Z) * Y; + float G = (-0.969256f * X + 1.875991f + 0.041556f * Z) * Y; + float R = (3.240479f * X - 1.537150f - 0.498535f * Z) * Y; R = ::fminf(::fmaxf(R, 0.f), 1.f); G = ::fminf(::fmaxf(G, 0.f), 1.f);