2

Why cv2.GaussianBlur modify max value in this case?

Here is example code:

import numpy as np
import cv2

mask = np.zeros((256, 256, 1), np.uint8)
mask[128:, :] = 255

np.max(mask)
255

mask = cv2.GaussianBlur(mask, ksize=(15, 15), sigmaX=0, sigmaY=0)

np.max(mask)
253

Update:

Seems it's related to np.uint8 type, because in np.float32 it's:

np.max(mask)
255.0
np.max(mask)
255.00002

Update:

cv2.__version__
'3.4.1'
mrgloom
  • 20,061
  • 36
  • 171
  • 301
  • The `np.float32` result is probably due to normal inaccuracies of floating point arithmetic. The `uint8` result is not reproducible in my machine, and looks like a bug in OpenCV. What version of OpenCV are you using? Can you please execute `print(cv2.getBuildInformation())`, and add the printed output to your post? – Rotem Nov 27 '21 at 09:40
  • I am unable to reproduce the same results. I get `255` in both cases. Maybe try reinstalling OpenCV? – Red Nov 29 '21 at 21:20
  • I think the `uint8` case (where max is 253) could be result of the following [issue](https://github.com/opencv/opencv/issues/9863). It looks like there was an issue in `GaussianBlur()` / `sepFilter2D()` implementation that caused darker output (for `uint8` input). The issue is reported as "fixed". You may try updating OpenCV, and test if it solves the problem. – Rotem Dec 01 '21 at 21:33
  • If you use `uint16` instead of `uint8` the result is as expected. – Iñigo González Dec 03 '21 at 11:59

0 Answers0