You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cv2.GaussianBlur produces darker results than input #9863
sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, respectively (see getGaussianKernel for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
I don't think sigmaY==sigmaX when sigmaY=0 is valid anymore.
For example, bit-exact GaussianBlur kernels may break their main property of sum(k) == 1.0.
There are several options for handling that:
don't call bit-exact code if bit-exact kernel is not a good approximation
"good approximation" should be well defined
try to adjust approximated kernel with saving sum(k) == 1.0 property.
This looks like crazy process (and it is hard to define that), but there is already special cases for sigma=0 and ksize=3,5,7 (these kernels are not accurate approximations from original formula)
Adjusting of approximated kernels in case of sepFilter2D() doesn't look good anyway (it is GaussianBlur approach only)
Activity
catree commentedon Oct 16, 2017
Looks like the discrepancy is only for
CV_8Utype?More tests with different Gaussian kernel sizes:
ksize=11,sigma=30:ksize=41,sigma=30:ksize=121,sigma=30:ksize=151,sigma=30:Full code:
antmarot commentedon Jan 24, 2019
I had the same issue.
For anyone wondering, you can use
getGaussianKernelandsepFilter2Dto avoid the issue.alalek commentedon May 4, 2019
What issue to avoid?
Results from experiments above shows the same numbers:
Difference is observed between 8U / 32F cases.
Proper way for making of these experiments is to drop pixels affected by borders at least (probably they are handled in a different ways).
catree commentedon May 6, 2019
I am using OpenCV 3.4.
On a big image:
Setting explicitly
sigmaX=30, sigmaY=30:On a small image (snake) (old code):
On a small image (snake) (new code):
Code:
Details
When
sigma1==sigma2, it should use IPP, otherwiseocvSepFilter.The documentation says:
sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, respectively (see getGaussianKernel for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.I don't think
sigmaY==sigmaXwhensigmaY=0is valid anymore.JohnGu9 commentedon Jul 13, 2019
I had the same issue.
I guess that opencv makes an inaccurate approximation for int type data.
When data type is double, the issue no longer appear.
Python code:
alalek commentedon Oct 23, 2019
Problem has been introduced in bit-exact computation path.
Computation using floating-point numbers (32F/64F) looks well.
Main inaccurate calculations are performed during kernels conversion:
For example, bit-exact GaussianBlur kernels may break their main property of
sum(k) == 1.0.There are several options for handling that:
sum(k) == 1.0property.sepFilter2D()doesn't look good anyway (it is GaussianBlur approach only)