Skip to content

Instantly share code, notes, and snippets.

@ctralie
Created July 5, 2021 15:46
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 ctralie/4fa5fcb88e9c8eff3f452207c7d28612 to your computer and use it in GitHub Desktop.
Save ctralie/4fa5fcb88e9c8eff3f452207c7d28612 to your computer and use it in GitHub Desktop.
Colormaps
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
from skimage import data
from skimage.color import rgb2gray
from colorspacious import cspace_converter
I = data.astronaut()
I = rgb2gray(I)
cmaps = ['gray', 'magma', 'jet', 'RdGy']
res = 3
plt.figure(figsize=(len(cmaps)*res, 2*res))
x = np.linspace(0, 1, 1000)
for i, cmap in enumerate(cmaps):
rgb = cm.get_cmap(cmap)(x)[:, 0:3]
lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb)
plt.subplot(2, len(cmaps), i+1)
plt.scatter(x, lab[:, 0], 20, c=rgb)
plt.ylim([0, 100])
plt.title(cmap)
plt.xlabel("Scalar Value")
plt.ylabel("Lightness")
plt.subplot(2, len(cmaps), i+1+len(cmaps))
plt.imshow(I, cmap=cmap)
plt.axis("off")
plt.tight_layout()
plt.savefig("colormaps.png", bbox_inches='tight')
@ctralie
Copy link
Author

ctralie commented Jul 5, 2021

colormaps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment