From 6fe71bd27c56c13ef8014164f7e0384629c368db Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 18 Mar 2014 14:29:02 +0400 Subject: [PATCH] added 4 channels support to fnlm --- modules/photo/src/denoising.cpp | 10 ++++++---- modules/photo/src/fast_nlmeans_denoising_opencl.hpp | 4 ++-- modules/photo/test/ocl/test_denoising.cpp | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index 98bb4fc8bb..51aa4fe6a5 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -86,7 +86,9 @@ void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, float h, float hForColorComponents, int templateWindowSize, int searchWindowSize) { - if (_src.type() != CV_8UC3) + int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); + + if (type != CV_8UC3 && type != CV_8UC4) { CV_Error(Error::StsBadArg, "Type of input image should be CV_8UC3!"); return; @@ -97,7 +99,7 @@ void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, templateWindowSize, searchWindowSize)) Mat src = _src.getMat(); - _dst.create(src.size(), src.type()); + _dst.create(src.size(), type); Mat dst = _dst.getMat(); Mat src_lab; @@ -113,10 +115,10 @@ void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, fastNlMeansDenoising(ab, ab, hForColorComponents, templateWindowSize, searchWindowSize); Mat l_ab_denoised[] = { l, ab }; - Mat dst_lab(src.size(), src.type()); + Mat dst_lab(src.size(), CV_MAKE_TYPE(depth, 3)); mixChannels(l_ab_denoised, 2, &dst_lab, 1, from_to, 3); - cvtColor(dst_lab, dst, COLOR_Lab2LBGR); + cvtColor(dst_lab, dst, COLOR_Lab2LBGR, cn); } static void fastNlMeansDenoisingMultiCheckPreconditions( diff --git a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp index ad1d942547..5152379839 100644 --- a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp @@ -149,10 +149,10 @@ static bool ocl_fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, fastNlMeansDenoising(l_ab[0], l_ab_denoised[0], h, templateWindowSize, searchWindowSize); fastNlMeansDenoising(l_ab[1], l_ab_denoised[1], hForColorComponents, templateWindowSize, searchWindowSize); - UMat dst_lab(src.size(), src.type()); + UMat dst_lab(src.size(), CV_8UC3); mixChannels(l_ab_denoised, std::vector(1, dst_lab), from_to, 3); - cvtColor(dst_lab, dst, COLOR_Lab2LBGR); + cvtColor(dst_lab, dst, COLOR_Lab2LBGR, src.channels()); return true; } diff --git a/modules/photo/test/ocl/test_denoising.cpp b/modules/photo/test/ocl/test_denoising.cpp index 745a45745f..c4a9f05f31 100644 --- a/modules/photo/test/ocl/test_denoising.cpp +++ b/modules/photo/test/ocl/test_denoising.cpp @@ -72,9 +72,9 @@ OCL_TEST_P(FastNlMeansDenoising, Mat) } } -typedef FastNlMeansDenoisingTestBase fastNlMeansDenoisingColored; +typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored; -OCL_TEST_P(fastNlMeansDenoisingColored, Mat) +OCL_TEST_P(FastNlMeansDenoisingColored, Mat) { for (int j = 0; j < test_loop_times; j++) { @@ -88,7 +88,7 @@ OCL_TEST_P(fastNlMeansDenoisingColored, Mat) } OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising, Combine(Values(1, 2), Bool())); -OCL_INSTANTIATE_TEST_CASE_P(Photo, fastNlMeansDenoisingColored, Combine(Values(Channels(3)), Bool())); +OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored, Combine(Values(3, 4), Bool())); } } // namespace cvtest::ocl -- 2.34.1