Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Definition

The histogram (French: histogramme) may be the simplest tool for image processing; it can be seen on cameras and even some smartphones, when shooting. It depicts how the intensities of the pixels are distributed. It is the discrete function hh such that

h(i)=nih(i) = n_i

where nin_i is the number of pixels with intensity ii.

The code below shows an image and two associated histograms. The histograms are displayed as a bar plot, constituted as a set of bins. The number (hence the width) of the bins are chosen by the user; in the example below, we choose 128 bins and 16 bins. Both histograms lie on [0,255][0,255] which are the intensity range of the image.

<Figure size 360x360 with 1 Axes>
<Figure size 864x288 with 2 Axes>

We distinguish two “modes” on the histogram. The one on the left (intensities around 75) corresponds to the dark tones in the image (mainly the background). The one on the right (intensities around 180) corresponds to the light tones (the petals and the center).

Histogram transformations

A histogram transformation consists of applying a mathematical function to the intensity distribution. Generally, the transformations are useful to improve the visual quality of an image, but are rarely needed inside an automatic processing.

The transform, denoted TT, is applied to the pixel intensities to change their values:

j=T(i)j = T(i)

where jj and ii are respectively the intensities of the new and the original image. As a consequence, the histogram of the new image differs from the histogram of the original image.

Below are some common transformations (we assume the pixel intensities to lie in [0,1][0,1]).

Negative image

T(i)=1−iT(i) = 1-i
Negative image: the gray levels are reversed.

Figure 2:Negative image: the gray levels are reversed.

Gamma correction

T(i)=iγT(i) = i^\gamma
Gamma correction modifies the coulors of an image acquired by an electronic system,
it is used to take into account the non-linear sensibility of human eyes to the light.
Here, \gamma=0.4

Figure 3:Gamma correction modifies the coulors of an image acquired by an electronic system, it is used to take into account the non-linear sensibility of human eyes to the light. Here, γ=0.4\gamma=0.4

Histogram spreading

(French: étalement d’histogramme)

T(i)=i−iminimax−iminT(i) = \frac{i-i_\text{min}}{i_\text{max}-i_\text{min}}

where imini_\text{min} and imaxi_\text{max} are respectively the minimum and maximum intensities in the image.

Histogram spreading enhances the contrast by “dilating” the histogram to the whole intensity interval.

Figure 4:Histogram spreading enhances the contrast by “dilating” the histogram to the whole intensity interval.

Histogram equalization

(French: égalisation d’histogramme)

T(i)=1MN∑k=0inkT(i) = \frac{1}{MN} \sum_{k=0}^i n_k

where MM and NN are the image size and nkn_k is the number of pixels with intensity kk. This transformation aims to spread the histogram over the entire intensity range, and to make the histogram as flat as possible. A consequence is an increase of the image contrast. It is a fully automatic method that does not require any parameters to be set. The demonstration of this equation is available in [Gonzalez 2010, section 3.3.1].

Histogram equalization is another contrast enhancing and tends to make the details more visible.

Figure 5:Histogram equalization is another contrast enhancing and tends to make the details more visible.

Thresholding

The histogram is sometimes very useful to segment the image in two classes, that is to distinguish the objects in the image with respect to their gray level. Indeed, if the histogram shows clearly two modes (i.e. two “bumps”), a threshold TT can be defined between these two modes, then apply a thresholding on the pixels, such that:

  • if the pixel level is lower that TT, then the pixel is in class 0 (displayed in black in Figure 6),

  • otherwise, the pixel is in class 1 (displayed in white in Figure 6).

Threshold with a threshold set to 0.45.

Figure 6:Threshold with a threshold set to 0.45.

Such a thresholding yields a binary image whose pixels have only two values. Several methods exist that compute the threshold automatically, such as Otsu’s method.