From 131c09cf76a2f8770432216409c4546aa9cfb74f Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Wed, 19 Dec 2018 15:09:24 +0300 Subject: [PATCH] Fixed medianBlur implementation for hi-resolution images --- modules/imgproc/src/median_blur.cpp | 10 +++++----- modules/imgproc/test/test_filter.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/imgproc/src/median_blur.cpp b/modules/imgproc/src/median_blur.cpp index e5e6af82e5..a07b6d6e18 100644 --- a/modules/imgproc/src/median_blur.cpp +++ b/modules/imgproc/src/median_blur.cpp @@ -282,10 +282,10 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) for ( ; luc[c][k] < j+r+1; ++luc[c][k] ) { #if CV_SIMD256 - v_fine += v256_load(px + 16 * MIN(luc[c][k], n - 1)) - v256_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0)); + v_fine = v_fine + v256_load(px + 16 * MIN(luc[c][k], n - 1)) - v256_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0)); #elif CV_SIMD128 - v_finel += v_load(px + 16 * MIN(luc[c][k], n - 1) ) - v_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0)); - v_fineh += v_load(px + 16 * MIN(luc[c][k], n - 1) + 8) - v_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0) + 8); + v_finel = v_finel + v_load(px + 16 * MIN(luc[c][k], n - 1) ) - v_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0)); + v_fineh = v_fineh + v_load(px + 16 * MIN(luc[c][k], n - 1) + 8) - v_load(px + 16 * MAX(luc[c][k] - 2 * r - 1, 0) + 8); #else for (int ind = 0; ind < 16; ++ind) H[c].fine[k][ind] += px[16 * MIN(luc[c][k], n - 1) + ind] - px[16 * MAX(luc[c][k] - 2 * r - 1, 0) + ind]; @@ -321,10 +321,10 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) CV_Assert( b < 16 ); } } + } #if CV_SIMD - vx_cleanup(); + vx_cleanup(); #endif - } } #undef HOP diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index b345994405..963de092e2 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -2200,4 +2200,15 @@ TEST(Imgproc_Filter2D, dftFilter2d_regression_10683) EXPECT_LE(cvtest::norm(dst, expected, NORM_INF), 2); } + +TEST(Imgproc_MedianBlur, hires_regression_13409) +{ + Mat src(2048, 2048, CV_8UC1), dst_hires, dst_ref; + randu(src, 0, 256); + + medianBlur(src, dst_hires, 9); + medianBlur(src(Rect(512, 512, 1024, 1024)), dst_ref, 9); + + ASSERT_EQ(0.0, cvtest::norm(dst_hires(Rect(516, 516, 1016, 1016)), dst_ref(Rect(4, 4, 1016, 1016)), NORM_INF)); +} }} // namespace