Image Enhancement in
the Spatial Domain
Histogram Processing
Some figures are provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Image Histogram
• Image Histogram
– digital image with gray levels [0, L-1]
– p(rk) = nk/N, probability of occurrence of gray level rk
– rk is the kth gray level
– nk = number of pixels with kth gray level
– N = total number of pixels
– k = 0, 1, 2, 3, 4, 5 . . ., L-1
Image Histogram
• p(rk) is the probability of the occurrence of gray-
level rk
• is the probability density function (PDF) of
the variable ,
p(rk)
rk
Image Histogram
• Histogram can tell you a lot about an image
• Gray level distribution
• It can be modeled by a statistical distribution (red line)
p(rk)= nk/N
rk
Image Histogram
• Gray level distribution helps define intensity
threshold
T(r)
p(rk)= nk/N
rk
Threshold
Image Histogram
• Histograms are not unique. Two images below
give the same image histogram.
• No spatial information is captured
Image Histogram
• Image types
Bright Image Dark Image
P(rk) P(rk)
rk rk
Image Histogram
• Image types
Low Contrast High Contrast
P(rk) P(rk)
rk rk
Some
Examples
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Contrast Stretching
Low Contrast
L-1 T(r)
P(rk)
s
r
0 r L-1
P(sk)
s
Contrast Compressing
High Contrast
L-1
P(rk) T(r)
r s
0 r L-1
P(sk)
s
Histogram Equalization
• We want an image with equally many pixels at every
gray level, or the output intensity approximately
follows a uniform distribution.
• That is, a flat histogram, where each gray level, rk,
appears (N/rm) times
– where “rm” is the maximum gray level
– N is number of pixels in the image
• Example
– https://demonstrations.wolfram.com/HistogramEqualization/
Histogram Equalization
• The weighted cumulative distribution function (CDF) of r is
represented by (in continuous form), (T is the transformation
function)
• This transformation function seeks to generate an output
image with a uniform (flat) probability density function (PDF),
independently of the form of
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Use T(r) to equalize the histogram
• Assume the input variable r has been
normalized between [0,1]
• s = T(r), there are two properties
– (a) T(r) is single-valued in the interval 0 <= r <= 1
– (b) 0 <= T(r) <= 1 for 0 <= r <= 1
Conditions (a) and (b)
• (a) T(r) is single-valued and non-decreasing in the interval
0 <= r <= 1
– Can preserve the order from black to white in the gray
scale.
– Can preserve the basic appearance of an image.
• (b) for 0 <= r <= 1, 0 <= T(r) <= 1
– Can guarantee a mapping that is consistent with the
allowed range of pixel values. No intensity rescaling is
needed.
Discrete approximation of T
• Let’s look at the discrete approximation
sk is the output continuous intensity value, 0 <= sk <= L-1
rk is the input continuous intensity value, 0 <= rk <= L-1
nj is number of pixels with the jth gray level
k = 0, 1, 2, 3, . . L-1 (gray levels)
Example
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
sk = T(rk) sk
T
Input image New image
rk
Total number of pixels = 64*64 = 4096 pixels
23-1=7
k 28-1=255
rk
Pr(rk)
Sk*(1/7)
Gray
levels
Stretching Compressing Compressing
Example
http://www.mathworks.com/help/toolbox/images/ref/histeq.html
nk
Image rk
Histogram
Notice, this is not normalized, y axis is nk.
To normalize, let y axis = p(rk)= nk /N
Example
sk
nk
rk rk
stretching compressing
Histogram
Notice, this is not normalized, y axis is nk.
To normalize, let y axis = p(rk)= nk /N
Example
sk
nk nk
rk T(r) sk
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Histogram Equalization
• Can significantly improve image appearance
– Automatic
– users doesn’t have to perform manual windowing or
manual gray level slicing
• Nice pre-processing step before image comparison
– Account for different lighting conditions
– Account for different camera/device properties
Local Enhancement
• Histogram equalization is a global operation
– Each pixel is processed based on information of the entire
image
– Often enhances global details
• We would like to enhance details over small areas
– Each pixel is processed based on information of a small
area/sub-image
Local Histogram Equalization
place result
(x,y) in (x,y)
Result
calculate histogram
using neighborhood of mxm
about (x,y)
Local Histogram
• Apply histogram equalization about a
neighborhood around (x,y)
• Transform the gray level for pixel (x,y)
• Move the neighborhood over the rest of
the image
Local Histogram
Reveals detail in local areas
Original Global Histogram Local Histogram
Histogram Specification
• It is useful sometimes to be able to specify the shape of the
histogram that we wish the processed image to have
• Histogram specification is also known as histogram matching
• Let be the intensity of the input image
• Let be the PDF (probability density function) of the
input image
Histogram Specification
• Let be the PDF (probability density function) of the
input image
Input image
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Histogram Specification
• The histogram equalized image of the input image
A lot of low intensity
pixels are mapped to the
high intensity values
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Histogram Specification
• Given the specified PDF , compute all values of the
transformation function
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Histogram Specification
• For each value of (rounded to integer), find the
corresponding value of so that (rounded to integer)
is closest to
• Generate the histogram-
specified image by
mapping every equalized
pixel with value to the
corresponding pixel with
value
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com