Пример #1
0
cmap = 'viridis'  # The optimized version of this colormap is cividis!

# Get original RGB/Jab
t = time()
rgb1, jab1 = cmu.get_rgb_jab(cmap)

# Get CVD RGB/Jab
rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1, severity=100))

# Make perceptual deltas (for a' vs. b') straight
# Need to set a and b before straightening J
jab3 = cmu.make_linear(jab2)
rgb3 = cmu.convert(jab3, cmu.CSPACE2, cmu.CSPACE1)

# Linearize J'
jab4, jab5 = cmu.correct_J(
    jab3)  # This will create a figure showing the J bounds
if jab4 is not None:
    rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1)
    rgb4 = np.clip(rgb4, 0, 1)
if jab5 is not None:
    rgb5 = cmu.convert(jab5, cmu.CSPACE2, cmu.CSPACE1)
    rgb5 = np.clip(rgb5, 0, 1)

#%% Figure: Iterations for optimization

fig = plt.figure(figsize=(25, 12), dpi=500)

# Plot original colormap properties
ax = plt.subplot(5, 5, 1)
plt.title('Input', fontsize=FLABEL)
cmu.plot_colormap_info(fig, rgb1, sp=[5, 5, 1], show=False)
Пример #2
0
import cmaputil as cmu
import cmaputil.cvdutil as cvu

# Globals
FLABEL = 20
FAX = 16

# Input colormap name
cmap = 'viridis'

# Optimize
rgb1, jab1 = cmu.get_rgb_jab(cmap)  # Original colormap
rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1))  # CVD colormap
jab3 = cmu.make_linear(jab2)  # Uniformize hue (a' vs. b')
_, jab4 = cmu.correct_J(jab3)  # Linearize J'

# Convert back to sRGB
rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1)
rgb4 = np.clip(rgb4, 0, 1)

# Resimulate CVD in case corrections took the map outside CVD-safe space
rgb4 = cvu.get_cvd(rgb4)

#%% Creat CDPS plots (shown in Fig 1 and 5 of the paper)

# Import test data
img_name = 'example_nanosims_image.txt'  # Image used for paper
img = np.loadtxt(img_name)[45:, :-45]  # Make square
high = 3
low = -1  # Std. Dev bounds for normalizing