Skip to content

Instantly share code, notes, and snippets.

@endolith
Created February 20, 2016 01:28
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 endolith/bb2d5031f6bd71ebb536 to your computer and use it in GitHub Desktop.
Save endolith/bb2d5031f6bd71ebb536 to your computer and use it in GitHub Desktop.
Color space curve
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 2015
"""
from __future__ import division, print_function
from colorpy.colormodels import lab_from_xyz, xyz_from_rgb, rgb_from_irgb
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure(1, figsize=(10, 9))
ax = fig.add_subplot(1, 1, 1, projection='3d')
def color_space_curve(colors, colorspace='RGB', lutsize=51, corners=None):
cmap = cm.get_cmap(colors, lut=lutsize)
for i in xrange(0, lutsize-1):
rd1, gn1, bl1 = cmap(i )[:3]
rd2, gn2, bl2 = cmap(i+1)[:3]
if colorspace == 'Lab':
L1, a1, b1 = lab_from_xyz(xyz_from_rgb(rgb_from_irgb(
(rd1*255, gn1*255, bl1*255))))
L2, a2, b2 = lab_from_xyz(xyz_from_rgb(rgb_from_irgb(
(rd2*255, gn2*255, bl2*255))))
ax.plot([a1, a2], [b1, b2], [L1, L2],
color=(rd1, gn1, bl1), markeredgecolor=(rd1, gn1, bl1),
marker='o', lw=2,
)
ax.set_xlim3d(-115, 115)
ax.set_ylim3d(-115, 115)
ax.set_zlim3d(0, 100)
ax.set_zlabel("L*")
ax.set_xlabel("a*")
ax.set_ylabel("b*")
elif colorspace == 'RGB':
ax.plot([rd1, rd2], [gn1, gn2], [bl1, bl2],
color=(rd1, gn1, bl1), markeredgecolor=(rd1, gn1, bl1),
marker='o', lw=2,
)
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 1)
ax.set_xlabel("red")
ax.set_ylabel("blue")
ax.set_zlabel("green")
else:
raise ValueError('colorspace not understood')
color_space_curve('afmhot', 'RGB')
color_space_curve('hot', 'RGB')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment