May 27, 2004


Histograms - Introduction

An intensity histogram is a graph, plotting the number of pixels (or fractional area) with a specific gray level vs. the gray level value.

The "leaves" are a distinctly lighter shade than the background, and have less total area than the background.  We thus expect the histogram to have two peaks - a taller one at lower intensity, and a smaller one to the right, at higher intensity.  This is true if higher pixel values are shown with ligher shades of gray (i.e. black = 0, white = 255).  In NIH Image, Scion Image and ImageJ, the opposite convention is true, that is black = 255 and white = 0.  This convention comes from NIH Image being originally developed to analyze exposed film, where the higher the signal, the greater the exposure, and the darker the film.  The opposite convention is used by Lispix (black = 0, white = 255), which was originally developed, among other things, for analysis of x-ray maps and electron diffraction patterns, where higher intensity  or more signal corresponds to lighter shades of gray.

This section done with ImageJ

To demonstrate the inverted brightness convention, merely move the mouse over the leaves or over the background, noting the pixel values shown below the tools: .


Since the image is noise, that is that there is considerable scatter of intensity values, an averaged measurement may be more convincing.  Using the rectangle selection tool , draw a rectangle within one of the leaves:


Analyze / Measure gives the mean value (91.1).  Note that the area is given in inches, as the default scale is 72 pixels / inch (See Analyze / Set Scale).
To get the corresponding measurement for the background, drage the rectangle to the background by using any point INSIDE as a handle.

Before measuring, I set the scale to pixels using Analyze / Set Scale. Typing in the Distance in Pixels as 0, or putting pixels as the Unit of length will result in no scaling, which results in the settings shown on the right, if Analyze /Set Scale is used a second time.

Then, Analyze /Measure shows the results - in the same Results window, if it has not been closed.  The measure command will not pop the Results window.  If it is hidden, you can view it using Window / Results.

Note - the Results window accumulates measurements unless they are cleared (Analyze / Clear Measurements) or the Results window is closed.

Measurements can be cut and pasted directly into Excel.

The measurements show that the leaves (line 1) have lower intensity values than the background (line 2).  To actually show them as darker than the background, use Image / Lookup Tables / Invert LUT.

Default LUT

Inverted LUT

This section done with ImageJ


If the histogram appears backwards, make sure that Invert Pixel Values is checked in the Options -> Preferences... box.

In Scion Image, inverting the pixel values does not affect the appearance of the histogram. It will always appear backwards (small peak to the left). Same with ImageJ

The large peak corresponds to the dark gray background, and the smaller peak to the right corresponds to the 'leaves'. These features are probably contamination - the sample was a 'clean' silicon surface.

  • Move the red band around in the LUT window ...

(shown sideways)

... until the 'leaves' are red:
  • Adjust the threshold sliders to make the leaves red.

  • Analyze -> Show Histogram menu, again, to see the change. (This will NOT make a new histogram window. It will change the old window.) (The histogram window does not reliably reflect the thresholds (red band in LUT window) on the PC. )

 Analyze / Show Histogram shows this.



We will now modify the pixel values (using the LUT window) to show what can happen to the histogram when the pixel intensites are scaled.

The image looks rather flat, because the full brightness range is not used.

After the enhancing the contrast, but before applying the LUT:

both windows show a modification of the default LUT (gray level scale) in that the line in the Map window no longer runs from the lower left to the upper right corner, and the LUT ramp graduated area has been squeezed toward the middle. A display similar to the Map window is shown on top of a histogram in the B&C window ( Image / Adjust / Brightness/Contrast ).

The image contrast is enhanced:

After applying the LUT, the image appearance is unchanged from its new enhanced appearance just after the Enhance Contrast menu is used, the Map and LUT windows are at their default settings (such as at startup), BUT this histogram has now changed:

The full range of gray levels (or pixel intensity values) are now used in the image, but the NUMBER of gray levels has not changed (each gray level is an integer value -- it cannot be split.  This is why the histogram has a comb-like appearance). The gray levels (as thin bars or lines in the histogram) have just been spread apart. The smaller peak still corresponds to the leaves.

   Note that the shading will not appear on the PC, and the histogram will be reversed left to right. In ImageJ, the histogram is not shaded, but a red bar appears underneath.

Note the Info window as the cursor is moved over the histogram. The spaces between the lines have 0 counts, because the original image had no gray level that would transform to these positions.

This shows the default of Image where darker objects (the leaves) have higher pixel values. The Invert Pixel Value option does change the interpretation of the values as far as the histogram and line profiles and measurements are concerned.

The histogram has been flipped horizontally, and the Info window has changed appropriately.

The image is very flat (part shown)

and the histogram has been squeezed


Sometimes histograms have a curious spiked or comb-like appearance. This is caused by scaling the pixel intensities up or down by a small amount. Example: the intensity range for an image is 0 - 230, and the contrast is increased to make the intensity range 0 - 255). This effect can be duplicated by repeating the above steps, but with a small change in the contrast rather than a large one.

Not much change will be seen in the image.

The Map window now looks like this


The image (of course) shows no change after this last step, but the histogram now has some 'missing teeth'.


This is because the histogram has been stretched slightly, the number of distinct gray levels remains the same, so there must be periodic gaps.

The converse happens when the contrast is decreased by a small amount:

The histogram has been squeezed slightly, so periodically, the gray levels pile up.

Combinations of gaps and teeth can occur, depending upon the treatment the image has received.

For the effects of filtering and image size on the histogram, see the exercise on Histograms, Filtering and Signal-to-Noise.