An Introduction To Biological Image Processing In ImageJ, Part 2: Color in Biological Imaging

Damian Dalle Nogare
8 min readJul 1, 2019

--

This is part 2 of a series. The first part can be found here.

In biological fluorescence imaging, since we are typically dealing with light in a narrow band of wavelengths corresponding to fluorophore emission spectra, we typically acquire black and white images, taking advantage of the high sensitivity of either photomultiplier tubes or black and white CCD cameras. Each pixel in these images only has a single intensity value. In RGB imaging (say for example a brightfield image captured on a color CCD camera), each pixel has three intensity values reflecting the intensity of each major color component, red, green and blue (RGB, in that order), each ranging from 0–255. .So for example a given pixel might have the intensity value 150, 10, 160, which means 150 units in the red, 10 units in the green and 160 units in the blue, which results in a purple color (mostly red and blue). The primary colors themselves are obtained by setting all of the other colors to 0, for example

A random image similar to the grey image from part 1 but in the RGB space is shown below.

An example 32 X 16 pixel RGB image

And when hovering over a pixel, ImageJ reports the three RGB values for intensity (in this case for pixel (12, 4), the values (154, 033, 145), again a kind of purple. The last value (#9a2191) is the hexadecimal code for that particular color, which we will not concern ourselves with here, but can be looked up here.

The RGB intensity values for the pixel at (12,4) in the above image, as reported by ImageJ.

In fluorescence imaging, the primary data is always always one or more black and white images.

Lookup tables for black and white images

When only one fluorophore is being imaged, it is in most cases best to leave the image in black and white. However, if we do want to show the image in color, or if we want to overlay multiple colors into a multi-channel image, we need to map the grayscale image to a color map. In imageJ, we can apply a lookup table (or LUT) to an image through the Image->Lookup Tables menu. A lookup table is a table where each possible grey value is assigned a corresponding RGB value representing a particular color. The final image is simply a 1:1 match between the grey values of the and the corresponding color values in the lookup table.

In fact, all of the black and white images we’ve seen so far have already had a lookup table applied, the “Grays” lookup table, which is the default in imageJ. Below is the same image with the “Grays” lookup table above and the “greens” lookup table below. The image above is identical to the one below, except for the fact that instead of intensities being mapped from black to white with varying shades of grey in between, they are mapped from black to green, with varying shades of green in between.

A 16 X 8 image with intensity encoded by the “Grays” lookup table
The same image with intensities encoded by the “Green” lookup table

For a more biological example, here is an identical image of mitochondria from zebrafish(taken with a GFP label), in the grey, green, and blue lookup tables

Mitochondria imaged with a GFP label visualized with the grey (left), green (middle) and blue (right) lookup tables

While these images are mathematically identical, the blue image is much harder to make out, simply because our eyes are less sensitive to colors in that part of the spectrum. This highlights the need to select an appropriate color map for our images, and not simply to use the one which corresponds to the fluorophore we happened to use. There is no shame in making our nuclear DAPI signal white instead of blue if it helps the reader understand the figure better.

The lookup tables above map intensity values to a single color. Other lookup tables map intensities to a gradient of colors, for example the spectrum lookup table maps intensities to the standard color ROYGBIV spectrum from red (low values) to violet (high values). The figure below compares the original black and white image to the spectral lookup table

An image of mitochondria in Zebrafish encoded using the “Grays” lookup table (left) and the “Spectrum” lookup table (right).

Keep in mind that lookup tables which map intensities to different colors can introduce visual artifacts due to the way our perception functions. For that reason, it is best practice to select a so-called “perceptual” map, where the colors have been selected to avoid such artifacts. One such map is parula, the default colormap for MatLab, or the mbl-viridis LUT in ImageJ. For example, here is a black and white image of a simple gradient of grey values

A gradient of intensity values from 0 to 255, encoded by the “Grays” lookup table

Notice how the grey values smoothly increase from black of the left edge to white on the right edge with no discontinuities.

Here is the same image in a non-perceptual lookup table (jet, above) and a perceptual color table (mpl-viridis, below)

The same gradient of intensity values as above, encoded by the “Jet” lookup table
The same gradient of intensity values as above, encoded by the “mpl-viridis” lookup table

While the perceptual map applied to the bottom image again seems to smoothly transition between purple on the left and yellow on the right, our eyes pick out apparent discontinuities on non-perceptual jet color map above (for example, in the middle transition between yellow and orange). These can give rise to figures in which boundaries that do not exist are shown as an artifact of the color map. You should always use a perceptual lookup table when applying this type of gradient color mapping. Good further discussion of this issue can be found here and here

Multi-color images and lookup tables

In ImageJ, we can combine multiple black and white images into a pseudocolor image. It is important to note that these are not RGB images, but 8 or 16 bit black and white images merged together, each with their own lookup table.

For example, consider the following two black and white images, membrane-GFP on the left and nuclear-mCherry on the right, from the same field

Black-and-white confocal images of membrane-GFP (left) and nuclear-mCherry (right)

We can apply an appropriate color map to each of these using the Image->Lookup Tables menu command above, to get the following result, selecting “Green” for the left image and “Red” for the right image.

Membrane and nuclear images with the green (membranes, left) and red (nuclei, right) lookup tables applied

However, keep in mind that these are still “black and white” images, in that they are just arrays of pixels with a single intensity value defining each pixel. All we have done here is change the color map from black-white to black-green on the left and black-red on the right, as we did above. In order to make a pseudocolor image, we use the “Image->Color->Merge Channels” command, which brings up the following dialog

Overlaying two black-and-white images to make a two-color 8-bit overlay image

Here, we can select which of our images we would like to be which color in the final color image. Here we are assigning the red color map to the nuclear image (C1 (red)), and the green color map to the membrane image* (C2 (green)). We can assign more images to the other colors in the list, but here we will work only with two channels.

This process will result in the following overlay image

The result of the above manipulation, a2-color 8-bit image (red and green channels), with the red channel selected

However, as we can see in the header, this is still an 8-bit image, not a color (RGB) image. What ImageJ has produced is a stack with two slices, each representing a single color, or channel, of the image, even though we are seeing two channels simultaneously in the display. The slider at the bottom controls which channel we are currently working on. In this case, the slider is all the way to the left, indicating we are working with channel 1. Helpfully, imageJ outlines the image with the current channel color as well, so you can see a thin red boundary around this image, as well as matching the color of the text above the image to the current image channel (in this case, red). All modifications we make, such as brightness or contrast, will only apply to channel 1 (the red, or nuclear channel in this case). If we switch to channel 2, this border, and the text in the header, becomes green, indicating that we are currently working with the green channel.

This separation is important because once we change this image into an actual RGB image (by the “Image->Type->RGB” color menu command, manipulations of things like relative intensity and contrast, as well as more sophisticated processing and various measurements on individual channels become far more difficult to perform. We can split this image back into its constituent black and white images using the “Image->Color->Split Channels command. Typically, we only convert images to RGB images when we are ready to include them in figures or presentations. Most of the time you are working in “color” images in imageJ, you will in fact be working with composite images of this type.

This is important to understand, because if we, for example, perform a measurement of the intensity, it will only measure the intensity of that channel. For example, consider the average intensity of the pixels in the circle in the figure below.

A two-color (red-green) 8 bit image with a circular region-of-interest (ROI) marked at the top-left

If we measure in channel 1 (the red), the intensity is 111.5. If we measure in channel 2, the intensity is 5.6. This is because when we perform this measurement on the individual channels of the image, what we are effectively doing is the following:

Channel 1 (left), average intensity in circle = 111.6. Channel 2 (right), average intensity in circle = 5.6

However, if we were to measure this same spot in an RGB image made from this composite, we would get an intensity value of 39.4. Why? Well, when measuring RGB image intensity, imageJ reports the average of each of the channel intensities. In this case, the intensity value is derived by the sum of the intensity in the green channel (5.6), the red channel (111.6) and the blue channel (0). So,

However, since the blue channel is meaningless in the biological context here, the reported RGB intensity value is also meaningless. Generally, you should never perform intensity measurements on RGB images.

In part three of this series, we will talk about three dimensional images, and the different ways we can project three dimensional images into two dimensions.

--

--