From 4ccdc785d0a5f45d9b8fdaac7221952e13ce408e Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Sat, 24 Aug 2019 16:57:42 -0700 Subject: [PATCH] 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/ --- lumps/colormap/colormap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lumps/colormap/colormap.py b/lumps/colormap/colormap.py index f07d54c3..8a46a733 100755 --- a/lumps/colormap/colormap.py +++ b/lumps/colormap/colormap.py @@ -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))