From f643964c6863dcbcdc83029c611b76cf9224a49b Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 11 Apr 2024 15:11:02 +0300 Subject: [PATCH] Added HAL function for popular bit-exact branch of GaussianBlur with sigma=0. --- modules/imgproc/src/hal_replacement.hpp | 25 +++++++++++++++++++++- modules/imgproc/src/smooth.dispatch.cpp | 28 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index 5c6497bd80..6d1f2a4272 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -855,7 +855,7 @@ inline int hal_ni_boxFilter(const uchar* src_data, size_t src_step, uchar* dst_d //! @endcond /** - @brief Blurs an image using a Gaussian filter. + @brief Blurs an image using a generic Gaussian filter. @param src_data Source image data @param src_step Source image step @param dst_data Destination image data @@ -880,6 +880,29 @@ inline int hal_ni_gaussianBlur(const uchar* src_data, size_t src_step, uchar* ds #define cv_hal_gaussianBlur hal_ni_gaussianBlur //! @endcond +/** + @brief Blurs an image using a symmetric Gaussian filter with square kernel and sigma=0. + @param src_data Source image data + @param src_step Source image step + @param dst_data Destination image data + @param dst_step Destination image step + @param width Source image width + @param height Source image height + @param depth Depth of source and destination image + @param cn Number of channels + @param margin_left Left margins for source image + @param margin_top Top margins for source image + @param margin_right Right margins for source image + @param margin_bottom Bottom margins for source image + @param ksize Width of kernel + @param border_type Border type +*/ +inline int hal_ni_gaussianBlurBinomial(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int depth, int cn, size_t margin_left, size_t margin_top, size_t margin_right, size_t margin_bottom, size_t ksize, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_gaussianBlurBinomial hal_ni_gaussianBlurBinomial +//! @endcond + /** @brief Computes Sobel derivatives @param src_depth Depth of source image diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp index 26566c7e03..d0f50a73bb 100644 --- a/modules/imgproc/src/smooth.dispatch.cpp +++ b/modules/imgproc/src/smooth.dispatch.cpp @@ -683,8 +683,22 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, if (src.data == dst.data) src = src.clone(); + + if ((sigma1 == 0.0) && (sigma2 == 0.0) && (ksize.height == ksize.width)) + { + Point ofs; + Size wsz(src.cols, src.rows); + Mat src2 = src; + if(!(borderType & BORDER_ISOLATED)) + src2.locateROI( wsz, ofs ); + + CALL_HAL(gaussianBlurBinomial, cv_hal_gaussianBlurBinomial, src2.ptr(), src2.step, dst.ptr(), dst.step, src2.cols, src2.rows, sdepth, cn, + ofs.x, ofs.y, wsz.width - src2.cols - ofs.x, wsz.height - src2.rows - ofs.y, ksize.width, borderType&~BORDER_ISOLATED); + } + CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint16_t*)&fkx[0], (int)fkx.size(), (const uint16_t*)&fky[0], (int)fky.size(), borderType), CV_CPU_DISPATCH_MODES_ALL); + return; } } @@ -720,8 +734,22 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, if (src.data == dst.data) src = src.clone(); + + if ((sigma1 == 0.0) && (sigma2 == 0.0) && (ksize.height == ksize.width)) + { + Point ofs; + Size wsz(src.cols, src.rows); + Mat src2 = src; + if(!(borderType & BORDER_ISOLATED)) + src2.locateROI( wsz, ofs ); + + CALL_HAL(gaussianBlurBinomial, cv_hal_gaussianBlurBinomial, src2.ptr(), src2.step, dst.ptr(), dst.step, src2.cols, src2.rows, sdepth, cn, + ofs.x, ofs.y, wsz.width - src2.cols - ofs.x, wsz.height - src2.rows - ofs.y, ksize.width, borderType&~BORDER_ISOLATED); + } + CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint32_t*)&fkx[0], (int)fkx.size(), (const uint32_t*)&fky[0], (int)fky.size(), borderType), CV_CPU_DISPATCH_MODES_ALL); + return; } }