colormap: use a crispier grayscale algorithm

Instead of averaging the RGB values, use a formula that better
approximates how the human eye sees color.

Formula was taken from this page:
http://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/
This commit is contained in:
Mike Swanson 2019-08-24 16:57:42 -07:00
parent 6566845f05
commit 4ccdc785d0

View file

@ -132,8 +132,9 @@ def invert_colors(colors):
result = []
for color in colors:
average = (color[0] + color[1] + color[2]) // 3
inverse = 255 - average
# Formula comes from ITU-R recommendation BT.709
gray = round(color[0]*0.2126 + color[1]*0.7152 + color[2]*0.0722)
inverse = 255 - gray
result.append((inverse, inverse, inverse))