Commit Graph

7 Commits

Author SHA1 Message Date
Mohammad Sohail Shaikh
c807cf9bca imgproc: fix stackBlur on sub-matrices and in place (#30739)
* imgproc: fix stackBlur on sub-matrices and in place

The vertical pass stepped between rows by the row width, so a destination
that is a region of a larger image was read and written at the wrong
rows, and pixels outside the region were overwritten. Step by the real
row stride instead.

The horizontal pass with a kernel of 9 or fewer pixels reads pixels left
of the one it writes, so stackBlur(img, img, ksize) blurred already
blurred values. Copy the row first when the blur runs in place.

* imgproc: limit the stackBlur in-place copy, parameterize its tests

In place, only the row pass for kernels up to 9 pixels wide reads pixels
it has already written. A kernel width of 1 skips the row pass, the row
branch for wider kernels reads the whole row before writing it, and the
column pass always works in place on the destination, so these calls no
longer copy the image.

Split the sub-matrix and in-place test into two TEST_P tests over depth,
channels and kernel size.
2026-11-11 14:44:47 +05:30
NIKHIL
54142329e9 imgproc: fix stackBlur results on full-range 16-bit images 🤖🤖🤖 (#30671)
* imgproc: fix stackBlur results on full-range 16-bit images

The 16-bit SIMD paths overflowed 32 bits in (sum * mul) >> shr and saturated when adding two 16-bit samples before the kernel multiply. Add the samples after widening, and divide as the scalar loops do, so SIMD and scalar agree and the result no longer depends on the thread count.

* imgproc: scale the stackBlur thread test with the machine's thread count

Restore the count with a guard so a throw can't leak it. Use an odd image width: with a width of 160, stripes at some thread counts, including 12, leave nothing to the scalar loop and the test passes on the unfixed code.

* imgproc: use 64-bit sums for large stackBlur kernels on 16-bit images

The largest sum is the largest absolute value times (radius + 1)^2, which no longer fits an int from radius 181 for CV_16U and radius 255 for CV_16S. Those radii now take the scalar loops with int64_t sums. Radii that fit keep the 32-bit SIMD paths.

* imgproc: use 64-bit sums for large stackBlur kernels on 8-bit images
2026-11-09 12:20:20 +05:30
satyam yadav
15fe69b5af Merge pull request #28250 from satyam102006:fix/stackblur-overflow-28233
imgproc: fix heap-buffer-overflow in stackBlur #28233 #28250

### Summary
Fixes a heap-buffer-overflow in `cv::stackBlur` when the kernel size is larger than the image dimensions 
### Changes
* Added input validation to clamp the kernel size to the image dimensions.
* Added a regression test (`regression_28233`) covering 1x1 and small image cases.

Fixes #28233
2025-12-22 11:22:12 +03:00
zihaomu
22de887c00 fix statckblur big kernel case 2024-04-30 18:07:21 +08:00
HAN Liutong
f617fbe166 Merge pull request #24132 from hanliutong:rewrite-imgproc2
Rewrite Universal Intrinsic code by using new API: ImgProc module Part 2 #24132

The goal of this series of PRs is to modify the SIMD code blocks guarded by CV_SIMD macro in the opencv/modules/imgproc folder: rewrite them by using the new Universal Intrinsic API.

This is the second part of the modification to the Imgproc module ( Part 1: #24058 ), And I tested this patch on RVV (QEMU) and AVX devices, `opencv_test_imgproc` is passed.

The patch is partially auto-generated by using the [rewriter](https://github.com/hanliutong/rewriter).

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2023-09-19 08:52:42 +03:00
Zihao Mu
17b98dd005 improve code style and Doc of stackblur. 2022-10-29 17:34:28 +08:00
Zihao Mu
2918071a3e add stackblur for imgproc. 2022-09-28 17:47:32 +08:00