Skip to content

Commit

Permalink
Merge pull request #20379 from zihaomu:stackblur
Browse files Browse the repository at this point in the history
Add StackBlur for imgproc
  • Loading branch information
asmorkalov committed Sep 29, 2022
2 parents 2d189e2 + 2918071 commit b403d37
Show file tree
Hide file tree
Showing 4 changed files with 1,638 additions and 0 deletions.
16 changes: 16 additions & 0 deletions modules/imgproc/include/opencv2/imgproc.hpp
Expand Up @@ -1620,6 +1620,22 @@ CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
Size ksize, Point anchor = Point(-1,-1),
int borderType = BORDER_DEFAULT );

/** @brief Blurs an image using the StackBlur.
The function applies and StackBlur to an image.
StackBlur can generate similar results as Gaussian blur, and the time does not increase as the kernel size increases.
It creates a kind of moving stack of colors whilst scanning through the image. Thereby it just has to add one new block of color to the right side
of the stack and remove the leftmost color. The remaining colors on the topmost layer of the stack are either added on or reduced by one,
depending on if they are on the right or on the left side of the stack.
Described here: http://underdestruction.com/2004/02/25/stackblur-2004.
Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
@param src input image. The number of channels can be arbitrary, but the depth should be one of
CV_8U, CV_16U, CV_16S or CV_32F.
@param dst output image of the same size and type as src.
@param ksize stack-blurring kernel size. The ksize.width and ksize.height can differ but they both must be
positive and odd.
*/
CV_EXPORTS_W void stackBlur(InputArray src, OutputArray dst, Size ksize);

/** @brief Convolves an image with the kernel.
The function applies an arbitrary linear filter to an image. In-place operation is supported. When
Expand Down
48 changes: 48 additions & 0 deletions modules/imgproc/perf/perf_blur.cpp
Expand Up @@ -253,4 +253,52 @@ PERF_TEST_P(Size_MatType, BlendLinear,
SANITY_CHECK_NOTHING();
}

///////////// Stackblur ////////////////////////
PERF_TEST_P(Size_MatType, stackblur3x3,
testing::Combine(
testing::Values(sz720p, sz1080p, sz2160p),
testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1)
)
)
{
Size size = get<0>(GetParam());
int type = get<1>(GetParam());
double eps = 1e-3;

eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;

Mat src(size, type);
Mat dst(size, type);

declare.in(src, WARMUP_RNG).out(dst);

TEST_CYCLE() stackBlur(src, dst, Size(3,3));

SANITY_CHECK_NOTHING();
}

PERF_TEST_P(Size_MatType, stackblur101x101,
testing::Combine(
testing::Values(sz720p, sz1080p, sz2160p),
testing::Values(CV_8UC1, CV_8UC4, CV_16UC1, CV_16SC1, CV_32FC1)
)
)
{
Size size = get<0>(GetParam());
int type = get<1>(GetParam());
double eps = 1e-3;

eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : eps;

Mat src(size, type);
Mat dst(size, type);

declare.in(src, WARMUP_RNG).out(dst);

TEST_CYCLE() stackBlur(src, dst, Size(101,101));

SANITY_CHECK_NOTHING();
}


} // namespace

0 comments on commit b403d37

Please sign in to comment.