Отвечая на свой вопрос, потому что я не нашел простого решения в StackOverflow:
def apply_custom_colormap(image_gray, cmap=plt.get_cmap('seismic')):
assert image_gray.dtype == np.uint8, 'must be np.uint8 image'
if image_gray.ndim == 3: image_gray = image_gray.squeeze(-1)
# Initialize the matplotlib color map
sm = plt.cm.ScalarMappable(cmap=cmap)
# Obtain linear color range
color_range = sm.to_rgba(np.linspace(0, 1, 256))[:,0:3] # color range RGBA => RGB
color_range = (color_range*255.0).astype(np.uint8) # [0,1] => [0,255]
color_range = np.squeeze(np.dstack([color_range[:,2], color_range[:,1], color_range[:,0]]), 0) # RGB => BGR
# Apply colormap for each channel individually
channels = [cv2.LUT(image_gray, color_range[:,i]) for i in range(3)]
return np.dstack(channels)
image_gray = cv2.imread('./lena.jpg', cv2.IMREAD_GRAYSCALE)
image_bgr = apply_custom_colormap(image_gray, cmap=plt.get_cmap('bwr'))
cv2.imshow('image with colormap', image_bgr)
cv2.waitKey(0)
Создает изображение:
![enter image description here](https://i.stack.imgur.com/5lzwM.jpg)