Skip to content

cv2.GaussianBlur produces darker results than input #9863

@homm

Description

@homm
System information (version)
  • OpenCV => 3.3.0 master
  • Operating System / Platform => Ubuntu 16.04 / x86_64
  • Compiler => gcc 5.4
Detailed description

GaussianBlur produces darker results than the input image.

Original Image:

gaus 0

>>> cv2.imwrite('gaus.30.cv2.png', cv2.GaussianBlur(im, (151, 151), 30))

gaus 30 cv2

$ gm convert gaus.0.png -blur 75x30 gaus.30.gm.png

gaus 30 gm

Images should look the same, but this is obvious, that produced by OpenCV is much darker.

Proof that results produced by OpenCV is wrong

In theory, Gaussian blur shouldn't change color distribution or lightness. So, lets calculate lightness of the images:

# Using Pillow
from PIL import Image 

def lightness(im):
    hist = im.histogram()
    return [
        sum(i*v for i, v in enumerate(hist[:256])) / im.width / im.height,
        sum(i*v for i, v in enumerate(hist[256:512])) / im.width / im.height,
        sum(i*v for i, v in enumerate(hist[512:])) / im.width / im.height
    ]

# [59.76, 69.08, 40.2]
print(lighnes(Image.open('gaus.0.png')))

# [59.73, 69.18, 39.94]
print(lighnes(Image.open('gaus.30.gm.png')))

# [53.86, 62.26, 36.22]
print(lighnes(Image.open('gaus.30.cv2.png')))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions