ENH: Add diverging colormap
Slicer lacked a perceptually uniform diverging colormap. According to matplotlib:
Diverging: change in lightness and possibly saturation of two different colors that meet in the middle at an unsaturated color; should be used when the information being plotted has a critical middle value, such as topography or when the data deviates around zero.
More info about why perceptually uniform colormaps should be used over older colormaps like Rainbow or Jet:
Some perceptually uniform colormaps have already been added to Slicer before, but they were not diverging: #582
Some examples:
- Correlation between localization of the electrode contacts in a normalized space and some clinical score (left: Rainbow; middle: ColdToHot; right: new diverging BlueRed):
- Visualization of compression / expansion of a deformation field (Jacobian) after a non-linear registration. When using the new diverging colormap, blue means expansion and red means compression (up: Rainbow; middle: ColdToHot; down: new diverging BlueRed):
When Rainbow or ColdToHot (similar to Jet) are used:
- It's difficult to mentally map a color with a value
- It's not easy to know where values are close to 0
- There is a lot of green areas, because green take a lot of room in the colormap
- Since yellow takes just a bit of room in the colormap, there seems to be a quick jump between green and red and a yellow line between them
Code used to generate the file:
import numpy as np
import matplotlib.pyplot as plt
colors = plt.get_cmap('RdBu')(range(255))
colors = colors[::-1] * 255
colors = colors.astype(np.uint8)
link = 'https://matplotlib.org/users/colormaps.html'
outputPath = '/tmp/BlueRed.txt'
opacity = 255
with open(outputPath, 'w') as f:
f.write('# Inspired form matplotlib colormaps: {}\n'.format(link))
for i, color in enumerate(colors):
s = '%d %d %d %d %d 255\n' % (i, i, color[0], color[1], color[2])
f.write(s)