Commit Graph

5 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
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