OpenCV's Gaussian smoothing changes the brightness

Tweet


OpenCV's Gaussian smoothing darkens the whole area of the image. This is because the calculation is done using integer values.

import numpy as np
import cv2
image=cv2.imread('image.bmp',cv2.IMREAD_COLOR)
output8ui=image.copy()
output64f=image.astype(np.float64)
for i in range(10000):
    if i%1000==0:
        print(np.average(output8ui),np.average(output64f))
    output8ui=cv2.GaussianBlur(output8ui,(15,15),7)
    output64f=cv2.GaussianBlur(output64f,(15,15),7)
cv2.imwrite('gauss8ui.bmp',output8ui)
cv2.imwrite('gauss64f.bmp',output64f)


Back