Created
July 5, 2021 15:46
-
-
Save ctralie/4fa5fcb88e9c8eff3f452207c7d28612 to your computer and use it in GitHub Desktop.
Colormaps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Author
ctralie
commented
Jul 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment