Skip to content

Instantly share code, notes, and snippets.

@aleroddepaz
Created April 5, 2013 12:40
Show Gist options
  • Save aleroddepaz/5318999 to your computer and use it in GitHub Desktop.
Save aleroddepaz/5318999 to your computer and use it in GitHub Desktop.
Script to convert RGB color to CIE color space
import sys
def rgb_to_xy(r, g, b):
X = 0.412453 * r + 0.357580 * g + 0.180423 * b
Y = 0.212671 * r + 0.715160 * g + 0.072169 * b
Z = 0.019334 * r + 0.119193 * g + 0.950227 * b
x = X / (X+Y+Z)
y = Y / (X+Y+Z)
return x, y
if __name__ == '__main__':
if len(sys.argv) != 4:
print "Incorrect number of parameters.\nUsage: %s r g b" % sys.argv[0]
sys.exit(1)
r, g, b = map(float, sys.argv[1:4])
print rgb_to_xy(r, g, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment