diff options
author | Stan Seibert <stan@mtrr.org> | 2011-08-03 17:28:09 -0400 |
---|---|---|
committer | Stan Seibert <stan@mtrr.org> | 2011-08-03 17:28:09 -0400 |
commit | d9982308f364abf082010c5db2c4b893f17f7bf6 (patch) | |
tree | 76dd91b0b68e125799a5f03a93c59f8056a528a4 /color/colormap.py | |
parent | acbeb1170dffc7b09ce4174cc5ef10a4ff0b3b1c (diff) | |
parent | 4e1047698bad5a600dd6a2aaa825667fc3617b07 (diff) | |
download | chroma-d9982308f364abf082010c5db2c4b893f17f7bf6.tar.gz chroma-d9982308f364abf082010c5db2c4b893f17f7bf6.tar.bz2 chroma-d9982308f364abf082010c5db2c4b893f17f7bf6.zip |
Merge Tony
Diffstat (limited to 'color/colormap.py')
-rw-r--r-- | color/colormap.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/color/colormap.py b/color/colormap.py new file mode 100644 index 0000000..b3761ae --- /dev/null +++ b/color/colormap.py @@ -0,0 +1,27 @@ +import numpy as np + +import matplotlib.pyplot as plt + +def map_to_color(a, range=None): + a = np.asarray(a) + if range is None: + range = (a.min(), a.max()) + + x = np.linspace(0, np.pi, 100) + + yr = np.cos(x)**2 + yr[x > np.pi/2] = 0.0 + yg = np.sin(x)**2 + yb = np.cos(x)**2 + yb[x < np.pi/2] = 0.0 + + #plt.plot(x, yr, 'r-', x, yb, 'b-', x, yg, 'g-') + #plt.show() + + ax = np.pi*(a - range[0])/(range[1]-range[0]) + + r = (np.interp(ax, x, yr)*255).astype(np.uint32) + g = (np.interp(ax, x, yg)*255).astype(np.uint32) + b = (np.interp(ax, x, yb)*255).astype(np.uint32) + + return r << 16 | g << 8 | b |