When to use it: color maps

I’m researching image processing techniques for my new job.  I’m finding lots of things that I never took the time to understand, even if I had encountered them.  One of them is color maps.  Color maps are ways to convert a set of scalar values into colors.  They can be used to visualize non-visual data, or enhance visual data.

Non-visual data

Frequently in science and engineering, an experiment or test generates data that is non-visual in nature.  For example, in my last job, a co-worker ran tests comparing the frequency of encountering a bug while varying inputs of a 2 input, 32-bit arithmetic operation.  He had a hypothesis that the frequency of encountering the bug was related to the number of on/true bits in the inputs, so he aggregated the data by the number of on/true bits in each input.  This generated a matrix of values: one axis for the number of true bits in one of the inputs, one axis for number of true bits in the other input, and the value of the matrix at X, Y was the number of times that the bug was encountered when each input had that many on/true bits.

It is immediately apparent that it is difficult to detect trends from a 32×32 matrix (1024 values) of integers.  Rather than look at numbers, it is far easier to detect a trend in this many values by visualizing it.

But how to visualize the data?  The data originated from an arithmetic operation.  There is no concept of color or shape in 32-bit inputs, even when aggregating the data.

One method of visualization is to assign a color for each frequency.  So if the minimum number of times the bug was encountered was 0, and the maximum was 100, we might choose 100 different colors and create a map:

99 #000011
100 #000000

Table 1 – Non-linear color map from white to black

Now we can plot a 32×32 square, where each element in the square contains one of the colors.  This makes trends immediately apparent.  It will be very visually obvious when the square shows a pattern such as a diagonal/horizontal/vertical black line, one or more black regions, and so on.

Therefore, a color map can help us translate non-visual data into a visualization that can help us spot trends or patterns.

Poorly-visualized data

The idea described above can be easily extended to a dataset that is poorly visualized, for example something with few colors or a small color range.  For example, a color map could be used to colorize old black & white photos (though if I had to guess, it would need to be done on a region-by-region basis).  In this case, each region would be assigned essentially a color, for example blue.  Pixels closer to white would be lighter blues, while pixels closer to black would be mapped to darker blues.  The person doing the colorizing could choose the color for the region, the lightest shade of the color, and the darkest shade of the color.  Then, a color map could be created for all the intensities in the region.  Each intensity would be mapped to a shade between the lightest & darkest shade.  The person performing the colorization could choose to make the colors very saturated by choosing very light & dark shades (ie, a large difference between the light & dark shade) for every region, or could choose to make the colors washed out by choosing light & dark shades that were close to each other.

The real challenge

Even brief reading on the topic of color maps has taught me that the real challenge in creating or using color maps is creating a good color map for the application that will not introduce artifacts.  These artifacts include disparate values being mapped to similar colors/luminances which can cause patterns to appear that may not actually appear, or may cause other patterns to disappear.  It’s also taught me that the default color maps in applications such as Matlab and Octave may not be a good fit for every application.  I’m not going to cover this topic, but here’s some great resources I found on it:

  • https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/
  • http://cresspahl.blogspot.com/2012/03/expanded-control-of-octaves-colormap.html

When to use it

Based on my very limited research and frankly zero experience with actually using or creating color maps, I think it’s still safe to conclude that a color map can be used to visualize non-visual data.  Compared to simply looking at numbers in a line or grid, visualizing data with color maps can reveal trends or patterns that are otherwise simply impossible to see.  Compared to greyscale visualization, color maps can impart meaning that may otherwise be missing.  This can be done with red/yellow to indicate “hot,” blue/green to indicate “cool,” light/dark to indicate infrequent/frequent – this is what data visualization experts excel at!

Color maps might also be useful to improve the visualization of poorly visualized data, by expanding/decreasing the contrast in a region, or even assigning color where none previously existed.

I’m still learning about this topic and would love to hear your additions or corrections to this post!  I would also love to be pointed toward good resources on color maps.  Just leave a comment below!


Leave a Reply

Your email address will not be published. Required fields are marked *