False Color Plots

False color (or more exactly pseudo color) can be useful when a device / detector records a grayscale image and a human has to interpret it. Fine differences are hard to see in grayscale images und a false color mapping allows us to map the 255 shades of gray of which ever pixel of any 8-bit grayscale image consists, to a full 3x8-bit color scale.

Here is a good mapping for scientific purposes, called Till's Palette:

class TillPalette(Palette):
    table = [ [0.0, 0.05, 0.30, 0.70, 1.00], # stops
              [0.0, 0.50, 0.00, 0.99, 0.99], # red
              [0.0, 0.99, 0.00, 0.00, 0.99], # green
              [0.0, 0.99, 0.99, 0.00, 0.00], # blue
            ]

This definition is done analog to TColor:CreateGradientColorTable in ROOT or similar to color_map in povray.

You can use the palette to map from gray scale to false color. I put the code needed into a Python module called colorscale. You can use it to check out the grayscale to RGB mapping:

import colorscale
conv = colorscale.GrayToRGB(colorscale.TillPalette())

for i in range(2**8):
    rgb = conv(i)
    print "Gray value:", i, "→", rgb

This prints:

Gray value: 0 → RGB value: (0, 0, 0)
Gray value: 1 → RGB value: (10, 20, 20)
Gray value: 2 → RGB value: (20, 40, 40)
Gray value: 3 → RGB value: (30, 59, 59)
Gray value: 4 → RGB value: (40, 79, 79)
Gray value: 5 → RGB value: (50, 99, 99)
Gray value: 6 → RGB value: (60, 119, 119)
Gray value: 7 → RGB value: (70, 139, 139)
[...]

(Complete output to be found here).

Visualizing Color Maps

http://bids.github.io/colormap/

pip install viscm
python -m viscm view jet

Resources

Comments