import numpy as np import matplotlib.pyplot as plt from colorspacious import cspace_convert from matplotlib.colors import ListedColormap # Define RGB anchor colors rgb_blue = np.array([0.0, 0.47, 1.0]) # Bright blue rgb_red = np.array([1.0, 0.2, 0.2]) # Bright red # Convert RGB to CAM02-UCS cam_blue = cspace_convert(rgb_blue, "sRGB1", "CAM02-UCS") cam_red = cspace_convert(rgb_red, "sRGB1", "CAM02-UCS") # Interpolate in CAM02-UCS space using smoothstep n = 256 t = np.linspace(0, 1, n) def f(t): return 3 * t**2 - 2 * t**3 smooth_t = f(t) # Interpolate cam_interp = np.outer(1 - smooth_t, cam_blue) + np.outer(smooth_t, cam_red) # Convert back to sRGB rgb_interp = cspace_convert(cam_interp, "CAM02-UCS", "sRGB1") # Clip to valid range and create colormap rgb_interp = np.clip(rgb_interp, 0, 1) cmap = ListedColormap(rgb_interp) # Plot to visualize plt.figure(figsize=(8, 1)) plt.imshow([np.linspace(0, 1, n)], aspect='auto', cmap=cmap) plt.axis('off') plt.title("Smoothstep Diverging Colormap") plt.show()