Skip to content

Instantly share code, notes, and snippets.

@dwblair
Created August 1, 2013 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwblair/6134758 to your computer and use it in GitHub Desktop.
Save dwblair/6134758 to your computer and use it in GitHub Desktop.
Generating a LUT in the format "DN,R,G,B" from the colormap data structure used by matplotlib.
import matplotlib as mpl
import matplotlib.cm as cm
import numpy as np
norm = mpl.colors.Normalize(vmin=0, vmax=255)
cmap = cm.spectral
m = cm.ScalarMappable(norm=norm, cmap=cmap)
for i in range(0,256):
vals=m.to_rgba(i)
print str(i) + "," + str(int(vals[0]*255)) + "," + str(int(vals[1]*255))+","+str(int(vals[2]*255))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment