next up previous
Next: About this document ... Up: digital_image Previous: Distances

Gray levels and histogram

The histogram is of essential importance in terms of characterizing a given image, and it is a global description of the appearance of the image. The histogram is the discrete version of the probability density distribution of all available gray levels of the image:

\begin{displaymath}h[i],\;\;i \in \{0,1,\cdots,255\}:\;\;
\mbox{probability of an arbitrary pixel to have gray level i}
\end{displaymath}

and the accumulative function is defined as:

\begin{displaymath}H[j]=\sum_{i=0}^j h[i],\;\;\;\;\;(j=0,1,\cdot,255) \end{displaymath}

Here is the code for finding the histogram of a given image:

\begin{displaymath}
\par
\;for\; (i=0; \;i<glevel;\; i++)\; H[i]=h[i]=0;
\par
\;...
...r
\;\; for\;(j=0;\;j<=i;\;j++)\;H[j]=H[j]+h[j];
\par
\;\}
\par
\end{displaymath}

where $glevel$ is the number of gray levels (256 for a 8-bit image) and note that as the density function, the histogram satisfies:

\begin{displaymath}\sum_{i=0}^{glevel-1} h[i] = H[glevel-1]=1 \end{displaymath}

Lenna_256_g.gif Lenna_256_g.hist

Lenna_256_c.gif Lenna_256_c.hist

For a gray level image to be properly displayed on screen, its pixel values have to be within a proper range. For a 8-bit digital image there are $2^8=256$ (from 0 to 255) gray levels. However, after applying certain processing operations to the input image, the gray levels of the resulting image are no longer necessarily within the proper range for display. In this case rescaling of the image is needed:


\begin{displaymath}y=f(x)=255\;\frac{x-x_{min}}{x_{max}-x_{min}} \end{displaymath}

where $x_{min}$ and $x_{max}$ are, respectively, the minimum and maximum pixel values in the image. The rescaling can be implemented by the following code:


\begin{displaymath}
\par
\;min=LARGE; max=-min;
\par
\;for (i=0;\; i<M;\; i++)
\...
...) \{
\par
\;\;\;\;img[i][j]=scale*(img[i][j]-min);
\par
\;\;\}
\end{displaymath}

where $LARGE$ is some large number (e.g., the largest floating point number representable in the computer) known to be greater than the highest pixel value.


next up previous
Next: About this document ... Up: digital_image Previous: Distances
Ruye Wang 2009-09-03