ONE, TWO, AND THREE DIMENSIONAL COLOR IMAGES December 12, 2007

Carl Heiles

Contents

1 INTRODUCTION 1

2 ONE-DIMENSIONAL COLOR: THE 8-BIT COLOR TABLE 2 2.1 The Basic Idea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.2 Linear Mapping, both Direct and Reversed . . . . . . . . . . . . . . . . . . . . . . . 3 2.3 Nonlinear Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.4 Why We Need Nonlinear Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.5 Considerations in Choosing a Color Table . . . . . . . . . . . . . . . . . . . . . . . . 4 2.6 The Colorbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 TWO-DIMENSIONAL COLOR: AN 8-BIT COLOR TABLE WITH 24-BIT COLOR 5 3.1 The Basic Idea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.2 Choosing a Color Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.3 Generating the color image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 Colorbars for 2-d Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4 THREE-DIMENSIONAL COLOR: WITH 24-BIT COLOR 8 4.1 Colorbars for 3-d Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

5 APPENDIX: THE IDL CODE FOR FIGURE 2 10

1. INTRODUCTION

This tutorial discusses the use of color in representing arrays of data. Normally we think of image display as just that—a way to display an image. However, you can combine more information into a single image by the combined use of color and intensity. Using color for these purposes is great, but using it intelligently is not trivial. There are three basic uses for color, and below we discuss each in the correspondingly-numbered section:

(1) Using a 256-entry color table to represent a single quantity. Consider this as a onedimensional mapping of the quantity into color. The most common example is the ordinary grayscale image, in which the degree of whiteness or blackness represents the value of the quantity represented in the image (such as light intensity). Many astronomers like to replace the simple grayscale with a colorscale because it’s easier to discern changes of color than small changes of brightness. However, this has its problems: firstly, almost 20% of the human male population is at least partly colorblind; secondly, color reproductions in printed journals are very expensive.

(2) Using 256 colors to represent the value of a single quantity, such as the mean velocity of a spectral line, together with 256 values of lightness (brightness of the color: black is zero, full brightness is maximum lightness of a particular color) to represent a different quantity, such as intensity of the spectral line. You are using two visually independent qualities—color and lightness—to represent two quantities, so this is a two-dimensional mapping onto the image plane.

(3) Using red, green, and blue (r,g,b) to represent the values of three independent quantities, with the 256 lightnesses of each color proportional to its quantity. For example, using red for IR, green for optical, blue for X-ray. This is a three-dimensional mapping onto the image plane. You can’t represent more than three dimensions in a color image because the eye is independently responsive to only three colors.

2. ONE-DIMENSIONAL COLOR: THE 8-BIT COLOR TABLE

2.1. The Basic Idea

In your computer’s memory, an image consists of a two-dimensional array of data value d in each pixel of the image in which d can take on 256 different values ranging from 0 to 255. On your screen, the image consists of projected light in each pixel, which we call the intensity I.

There is a one-to-one relationship between d and I, so there are also 256 different possibile values for I. Generally speaking, this relationship is specified by the “color table”. The color table is often nonlinear so as to emphasize weak or strong features. Sometimes it’s an equal mixtue of red, green, and blue (greyscale); sometimes the mixture is engineered to produce color. By “Intensity” (I), we mean the 256 different possible combinations of light intensity and color, one for each valuie of d.

2.2. Linear Mapping, both Direct and Reversed

The simplest mapping between data value d and intensity I is a linear one with

I = d  (1)

In this case, a data value d = 255 gives white and d = 0 gives black. This direct mapping is the default manner in which images are displayed on the computer screen: there is a black background on which the image is painted with increasing data values being increasingly white. However, on a piece of paper the relationship is usually reversed, because paper is white and provides a naturally white background. Thus, in this reversed mapping, we want to paint the image with increasing data values being increasingly black. This is also a linear mapping, but reversed:

I = 255 − d  (2)

Printed images usually look much better with the reversed mapping, because printers have a hard time giving a uniformly black area with no streaks. This is the first reason why printed images should be made with a reversed mapping. The second reason is that in scientific journals, images with the reversed mapping are reproduced much better. The third reason is that making the paper black uses lots of printer toner, which is expensive.

2.3. Nonlinear Mapping

The linear mapping is often not very useful because you usually want to highlight weak features or bright features; we’ll see an example below. The most commonly used nonlinear mapping uses a power law (this is the photographer’s “characteristic curve”) together with a “stretch”, which cuts off the image at dim and bright intensity levels:

I = 255 (\frac{d − d_{bot}}{d_{top} − d_{bot}} )^{γ} , d = d_{bot} → d_{top}  (3a)

I = 0, d ≤ d_{bot}  (3b)

I = 255, d ≥ d_{top}  (3c)

In a reversed mapping, you’d substitute (255 − d) for d in the above equations.

There is one other commonly used nonlinear mapping, the so-called “histogram equalization” technique. In this technique, the mapping is modified so that all of the 255 colors are used in an equal number of pixels. Read about it in IDL’s documentation on hist equal.

2.4. Why We Need Nonlinear Mapping

Never forget that the idea is to turn the data array into an image that conveys information to the brain. The idea is not to be so strictly quantitative that details of interest are obscured.

You want to bring out details of interest. For example, for many images of the interstellar gas you want to emphasize weak structures at the expense of the fidelity gained by a strict proportionality between image brightness and data value. To this end, choose a color table and experiment with the image transfer function, using the techniques discussed in BIDIDL. At minimum, this involves changing the span of the data values represented in the image and raising the data values within that span to a power: a power less than unity to emphasize weak features, larger than unity for strong ones.

2.5. Considerations in Choosing a Color Table

For images to be printed on paper, a grayscale color table is usually best because color reproductions are pretty bad unless you use an inkjet printer. However, for other purposes, such as lecture slides, a color table is often preferred because you can see more details.

THIS SECTION NEEDS WORK

I have, myself, not yet come upon the ideal color table. The ideal color table would:

1. Have a monotonically and smoothly changing color with intensity value.

2. Have no visual ambiguity: a non-colorblind person would never suffer any ambiguity about the relationship between color and intensity.

3. Have the most intense portions of the image be represented by the physiologically brightest color in the color table.

4. Have the least intense portions of the image not be represented by the physiologically dimmest color (which is blue), because it will not clearly show weak features against the black background of zero intensity.

Color Tables in common use do not satisfy all these conditions. For example, the very popular color table used by the VLA’s AIPS uses red for the most intense parts of the image; the physiologically brighter white represents a lower intensity level. Despite this departure from a purist philosophy, the AIPS color table is quite good. Many other color tables that people use are simply awful when considered from a visual, not to mention logical, perspective.

In my opinion, IDL provides four color tables that approach the ideal. Their names and numbers are: Hue Sat Lightness 1 and 2 (numbers 19 and 20); Hue Sat Value 1 and 2 (numbers 21 and 22). (For both of these, number 2 needs to be reversed because white is at the low-intensity end of the range). It also provides another color table which doesn’t satisfy these criteria very well but its colors are so striking that it is psychologically quite appealing (to me, at any rate); it’s Standard Gamma II (number 5). You can load these color tables either from xloadct or (preferably) using the IDL command loadct, nr (where nr is the number of the color table given above). You can also make any color table you choose and load it with tvlct; see §3.2.

2.6. The Colorbar

OK, you’ve carefully chosen your colortable and nonlinear transfer function and made a beautiful one-dimensional image that makes the mental impact you desire. You’re not done! There’s nothing more annoying than seeing a nice one-dimensional image without an indication of how the grayscale or color relates to data value. You do this with a colorbar. Shame on you for even thinking of generating a 1-d image without a colorbar! See Figure **** for an astronomical image, complete with colorbar.

3. TWO-DIMENSIONAL COLOR: AN 8-BIT COLOR TABLE WITH 24-BIT COLOR

3.1. The Basic Idea

Here, the idea is to use color to represent the value of a single quantity, such as the mean velocity of a spectral line, and use the lightness (apparent brightness of the color: black is zero, full brightness is maximum lightness) to represent a different quantity, such as the integrated intensity of the spectral line. This is a two-dimensional mapping onto the image plane. Figure 1 shows an example. The image is Hα data from the WHAM survey; color represents mean velocity, lightness represents the logarithm of the line brightness.

You accomplish this by making two images. One is a grey scale image of the intensity, and you can fiddle with its colortable (which, for grey scale, means the conversion from d to I discussed in §2. The other is a non-grey scale image of the velocity. Let’s call these two images I(x, y) and V (x, y), where (x, y) are the image coordinates.

Suppose you look at the V image, which is represeented by a 256-element colortable. It is uniformly bright in that it has no information about I. To insert this intensity information, you Fig. 1.— Example of a two-dimensional color image in which color represents the mean velocity of the Hα line, Obviously (we hope!), this image makes little sense with a black/white printer! make an intensity-modulated V image, which we’ll call V_{I}:

V_{I}(x, y) = \frac{I(x, y)}{I_{max}} × V (x, y)  (4)

This combines the two images into a single image in which color represents velocity and brightness the intensity.

3.2. Choosing a Color Table

You might think that a natural choice would be the spectrum, from red to blue, representing positive to negative velocities. However, this is an exceedingly poor choice because it ignores the fundamental fact that the human visual system has a very low sensitivity to blue light. Therefore, the brain will perceive all negative velocities, represented by blue, as less intense than the corresponding positive velocities, even though the line intensities are the same or larger.

In other words, you need to account for human physiology in the choice of the color table. If you do this properly, then the sensatation of color and velocity will be nearly orthogonal.

There is a purist version that maximizes ortthogonality. However, Tim Robishaw and I have found that a slight revision to this purist concept (namely, removing a bit of red to make more green) gives a color table that has a little more variation in distinguishable color. Figure 2, left panel, shows a “rainbow” color table, which contains the dark-looking saturated blue. In contrast, the right panel shows the physiologically orghogonal veresion: the saturated blue is brightened by adding other colors to make it a brighter pastel color.

Fig. 2.— Left, a “rainbow” color table; Right, the psychologically correct color table in which all colors are perceived to be of approximately equal brightness. This plot is best viewed in color!

3.3. Generating the color image

Having defined the color table, generating the color image is easy if you have the image of velocities; the velocities V range between two extremes. The velocities of interest have a smaller extent, and you choose this range to span the full color range. Call the limits of this range V_{min} and V_{max}. A common mistake is to make V_{min} and V_{max} too far apart, so you’re not gaining the full range of colors on the image. Be sure to experiment with these values!

3.4. Colorbars for 2-d Images

Without a colorbar, you’re not done! The colorbar has to indicate boh intensity and velocity. The colorbar is a rectangular area with two dimensions, so you use one for intensity and one for color as in our illustrative figure.

4. THREE-DIMENSIONAL COLOR: WITH 24-BIT COLOR

Here you want to represent three independent quantities by three independent, orthogonal-to-the-eye colors. Figure 3 shows an example. Red represents the Hα line intensity, green the 21-cm line intensity, and blue the XM band X-ray intensity.

You can use two color schemes. One is the obvious red, green, blue; these correspond directly to the three cones of sensitivity in the eye. Of course, this scheme is susceptible to the poor bluesensitivity of the human visual system, but sometimes this is an advantage when one of the images is less important. It really matters for which image you use blue! Experiment!

In principle, you can use the complements of (r,g,b), i.e. you can make a 3d image with [white - (r,b,g)]. These are the colors cyan, magenta, and yellow, which are cyan = (green + blue), magenta = (red + blue), yellow = (red + green). This color scheme like a reversed mapping, for which the image gets darker when the astronomical data values are higher. This endows this color scheme with a highly unusual property: regions with low signal are bright and have well-defined colors; regions with high signal are dark with poorly-defined colors. So this is the scheme of choice when displaying the velocity of weak features is important, and the velocities of strong features don’t matter.

4.1. Colorbars for 3-d Images

Without a colorbar, you’re not done! Colorbars for 3-d images are hard because paper and images are 2-d by nature, while the colorbar has to indicate intensities for 3 colors and how these colors appear to the eye with all of their different combinations. We have attacked this with the Fig. 3.— Example of a three-dimensional color image in which red, green, and blue represent different datasets. Obviously (we hope!), this image makes little sense with a black/white printer!

scheme shown in our example Figure 3. Here, a bar across the top of the image is divided into eight squares. The three leftmost squares give the characteristic curves for red, green, and blue, and are labeled with the quantity depicted. The five rightmost squares exhibit how the colors mix when combined. In each square, blue has a different intensity, constant within the whole square, running from 0, 0.25 … 1.0 of full intensity. Within each square, red is zero at the left and maximum at the right; green is zero at the bottom and maximum at the top. So the top right corner of each of these five squares is full red and green: the first square, with no blue, shows yellow and the last, with full blue, white.

5. APPENDIX: THE IDL CODE FOR FIGURE 2

This is the batch file (invoked with ’@‘) used to create the ps file for Figure 2. Note that loadct,0 is called after calling pseud0 ch!!

;CREATE THE WINDOW WITH BORDERS...
w_left=0.16
w_rght=0.05
w_bot=0.16
w_top=0.14
space=0.03
width=0.1
img_cbar_posns, w_left, w_rght, w_bot, w_top, space, width, $
        imgposn, cbarposn, f_hor, f_ver
;CREATE AN XWINDOW IF PS IS 0...
if ps eq 0 then window,7,xs=f_hor*500, ys= f_ver*400
;CREATE THE COLORTABLE...
pseudo_ch,colr
;IMPORTANT NOTE: WHEN USING NONDECOMPOSED COLOR (PS OR X WITH
;PSEUDOCOLOR), YOU ***MUST*** INCLUDE THE FOLLOWING STATEMENT; AND
;INCLUDING IT WITH DECOMPOSED COLOR IS OK:
loadct,0
if ps then psopen, 'pseudoplot.ps', xsize=5, ysize=4, /inch, /color, $
  /times, /bold, /isolatin1
;MAKE NICE AXES AND PS FONTS USING SYSTEM VARIABLES...
!p.font=ps-1
!p.thick=6

!x.thick=4
!y.thick=4
;WRITE THE COLORBAR BEFORE CALLING SETCOLORS...
colorbar, pos=cbarposn, crange=[0,255], rgb=colr, color=!black, $
  xtit=textoidl('Color, 0 \rightarrow 255');;;;, ps=ps
;CALL SETCOLORS FOR THE VECTORIZED PORTION OF PS...
setcolors, /sys
;DO THE PLOT...
plot, colr[*,0], /nodata, position=imgposn, /noerase, $
        xra=[0,256], /xsty, xtit='Image Intensity', $
        yra=[0,260], /ysty, ytit='Color Intensity' , color=!black
oplot, colr[*,0], color=!red
oplot, colr[*,1], color=!green, lines=2
oplot, colr[*,2], color=!blue, lines=3
indxcyan=where( colr[*,1] eq 255 and colr[*,2] eq 255, countcyan)
if countcyan ne 0 then oplot, minmax(indxcyan), [255,255], color=!cyan
indxcyan=where( colr[*,0] eq 255 and colr[*,2] eq 255, countcyan)
if countcyan ne 0 then oplot, minmax(indxcyan), [255,255],
color=!magenta
legend, ['Red', 'Green', 'Blue'], lines=[0,2,3],
colors=[!red,!green,!blue], $
        position=[20,100], thick=[6,6,6], textcolors=[!red,!green,!blue]
if ps then psclose
setcolors, /sys
;RETURN EVERYTHING BACK TO NORMAL...
!p.font=-1
!p.thick=0
!x.thick=0
!y.thick=0

It is a pleasure to thank Tim Robishaw for teaching me a lot, providing software, and constructive comments.