next up previous [pdf]

Next: Time-power amplitude-gain correction Up: Homework 1 Previous: Digital representation of numbers

Histogram equalization

bay
bay
Figure 1.
Digital elevation map of the San Francisco Bay Area.
[pdf] [png] [scons]

Figure 1.1 shows a digital elevation map of the San Francisco Bay Area. Start by reproducing this figure on your screen.

  1. Change directory to geo391/hw1/bay
  2. Run
    scons bay.view
    
  3. Examine the file byte.rsf which refers to the byte (unsigned character) numbers which get displayed on the screen.
    1. Open byte.rsf with a text editor to check its contents.
    2. Run
      sfin byte.rsf
      
      to check the data size and format.
    3. Run
      sfattr < byte,rsf
      
      to check data attributes. What is the maximum and minimum value? What is the mean value? For an explanation of different attributes, run sfattr without input.

Each image has a certain distribution of values (a histogram). The histogram for the San Francisco elevation map is shown in Figure 1.2. Notice the digitization artifacts. When different values in a histogram are not uniformly distributed, the image can have low contrast. One way of improving the contrast is histogram equalization.

hist
Figure 2.
Normalized histogram (solid line) and cumulative histogram (dashed line) of the digital elevation data.
hist
[pdf] [png] [scons]

Let $f(x,y)$ be the original image. The equalized image will be $F(x,y)$. Let $h(f)$ be the histogram (probability distribution) of the original image values. Let $H(F)$ be the histogram of the modified image. The mapping of probabilities suggests

\begin{displaymath}
H(F) dF = h(f) df
\end{displaymath} (1)

or, if we want the modified histogram to be uniform,
\begin{displaymath}
\frac{d F}{d f} = C h(f) 
\end{displaymath} (2)

where C is a constant. Solving equation 1.2, we obtain the mapping
\begin{displaymath}
F(f) = f_0 + C \int\limits_{f_0}^f h(\phi) d\phi\;,
\end{displaymath} (3)

where $f_0$ is the minimum value of $f$.

The algorithm of histogram equalization consists of the following three steps:

  1. Taking an input image $f(x,y)$, compute its histogram $h(f)$.
  2. Compute the cumulative histogram $F(f)$ according to equation (1.3). Choose an appropriate $C$ so that the range of $F$ is the same as the range of $f$.
  3. Map every pixel $f(x,y)$ to the corresponding $F(x,y)$.

Your task is:

  1. Among the Madagascar programs, find a program that implements histogram equalization. Hint: you may find the sfdoc utility useful.
  2. Edit the SConstruct file to add histogram equalization. Create a new figure and compare it with Figure 1.1.
  3. Check the effect of equalization by recomputing the histogram in Figure 1.2 with equalized data. Run
    scons hist.view
    
    to display the figure on your screen.`
  4. EXTRA CREDIT for implementing the histogram equalization algorithm independently.

from rsfproj import *

# Download data
Fetch('bay.h','bay')

# Window and taper
Flow('bay','bay.h',
     '''
     dd form=native |
     window f2=500 n2=1600 f1=50 n1=1050 |
     reverse which=1 |
     costaper nw1=50 nw2=50
     ''')

# Convert to byte form
Flow('byte','bay','byte pclip=99.9 allpos=y')

# Display
Result('bay','byte',
       '''
       grey crowd=0.85 title="Elevation of San Francisco Bay"
       ''')

# Histogram
Flow('hist','byte',
     '''
     dd type=float |
     histogram n1=256 o1=0 d1=1 |
     dd type=float
     ''')
Plot('hist',
     'graph label1=Value label2=Occurence title=Histogram')

# Cumulative histogram
Flow('cumu','hist','causint')

Result('hist','hist cumu',
       '''
       cat axis=2 ${SOURCES[1]} | scale axis=1 |
       graph label1=Value label2="Normalized Occurence"
       title=Histogram dash=0,1
       ''')

# ADD HISTOGRAM EQUALIZATION

End()


next up previous [pdf]

Next: Time-power amplitude-gain correction Up: Homework 1 Previous: Digital representation of numbers

2010-03-19