Professional Documents
Culture Documents
Lecture-5
2
of
36
Histogram Processing
In Statistics, Histogram is a graphical representation showing a visual
impression of the distribution of data.
An Image Histogram is a type of histogram that acts as a graphical
representation of the lightness/color distribution in a digital image. It
plots the number of pixels for each value.
The histogram of a digital image with gray levels in the range [0, L – 1]
is a discrete function:
h(rk) = nk for k = 0, 1, 2, ….., L – 1
Where:
rk : kth gray level (denote the intensities of an L-level digital image f(x,
y))
nk : # of pixels with having gray level rk
Massively useful in image processing, especially in segmentation
3
of
36
Histogram Processing
Example:
Image (left) has 256 distinct gray levels (8 bits)
Histogram (right) shows frequency (how many times) each gray
level occurs
x-axis shows the gray level intensities and y-axis shows the
frequency of intensities
4
of
36
Histogram Processing
E.g. K = 16, 10 pixels have intensity value = 2
Histograms: only statistical information
No indication of location of pixels
5
of
36
Histogram Processing
It is common practice to normalize a histogram by
dividing each of its values by the total number of
pixels in the image, denoted by n. Thus, a
normalized histogram is given by
p(rk) = nk / n, for k = 0, 1, 2, ….., L – 1.
Thus, p(rk) gives an estimate of the probability of
occurrence of gray level rk.
Note that the sum of all components of a normalized
histogram is equal to 1.
n is also known as MN (rows and columns of an
image)
6
of
36
Histogram of the Image
The horizontal axis of the histograms are values of rk and
the vertical axis are values of p(rk).
7
of
36
Histogram Sliding
Brightness is changed by shifting the histogram to left or
right.
+50
8
of
36
Histogram Sliding
Brightness is changed by shifting the histogram to left or
right.
- 30
9
of
36
Histogram in MATLAB
h = imhist (f, b)
Where f, is the input image, h is the histogram, b is number of bins
(tick marks) used in forming the histogram (b = 255 is the default)
We obtain the normalized histogram simply by using the
expression.
p = imhist (f, b) / numel(f)
numel (f): a MATLAB function that gives the number of elements
in array f (i.e. the number of pixels in an image).
10
of
36
Histogram in MATLAB
A histogram, A stem graph, A bar graph, A Plot graph
>> h = imhist(f);
>> bar (h);
>> stem (h);
>> plot (h);
11
of
36
Histogram Stretching
Contrast can be increased using:
1. Histogram stretching
2. Histogram equalization
Contrast is the difference between maximum and minimum pixel intensity. Contrast = 225.
12
of
36
Increasing Contrast
f(x,y) g(x,y)
Before
Contrast = 225
After
Contrast = 240
14
of
36
Contrast Stretching
Frequency of gray
Not monotonically
level values for an 8
increasing function
bits per pixel image.
18
of
36
Probability – CDF
CDF – Cumulative Distributed Function
Cumulative sum of values calculated by PMF
r
ds dT (r ) d
( L 1) pr ( w) dw ( L 1) pr (r )
dr dr dr 0
23
of
36
Histogram Equalization
Substituting this result: ds
( L 1) pr (r )
dr
to
dr
ps ( s ) pr (r )
ds
yields Uniform pdf
1 1
ps ( s ) pr (r ) , 0 s L 1
( L 1) pr (r ) L 1
24
of
36
Histogram Equalization
The formula for histogram equalisation in the discrete
case is given
k
( L 1) k
sk T (rk ) ( L 1) pr (rj ) nj
j 0 MN j 0
where
rk: input intensity
sk: processed intensity
nj: the frequency of intensity j
MN: the number of image pixels.
25
of
36
Example
A 3-bit 64x64 image has the following intensities:
M = 64, N = 64
k
( L 1) k
sk T (rk ) ( L 1) pr (rj ) nj
j 0 MN j 0
6
2 3 3 2 5
4 2 4 3 4
3 2 3 5 3
2
2 4 2 4
1
Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
34
of
36
Equalization Transformation Example
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)
No. of
0 0 6 5 4 1 0 0 0 0
pixels
k
n
j 0
j 0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 0 n
16 16 16 16 16 16 16 16
3.3 6.1 8.4
sx9 0 0 9 9 9 9 9
3 6 8
35
of
36
Equalization Transformation Example
No. of pixels
3 6 6 3 6
8 3 8 6 5
4
6 3 6 9
3
3 8 3 8
2
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Histogram equalization
36
of
36
Histogram Specification
Histogram
equalization
38
of
36
Histogram specification (cont.)
0, otherwise
0, otherwise
41
of
36
Histogram specification (cont…)
Find the histogram equalization transformation for the
input image
2
r r 2w r
s T (r ) ( L 1) pr ( w)dw ( L 1) dw
0 0 ( L 1) 2
L 1
1
z
Obtain the inverse transform: q G ( s k ) G 1
(T (rk ))
43
of
Histogram Specification (cont...)
36 Example
Consider again the 3-bit 64x64 image:
with z0 0, z1 1, z2 2, z3 3, z4 4, z5 5, z6 6, z7 7.
44
of
Histogram Specification (cont...)
36 Example
The first step is to equalize the input (as
before):
s0 1, s1 3, s2 5, s3 6, s4 6, s5 7, s6 7, s7 7
G ( z0 ) 0 G ( z1 ) 0 G ( z2 ) 0 G ( z3 ) 1
G ( z 4 ) 2 G ( z5 ) 5 G ( z 6 ) 6 G ( z 7 ) 7
Specified histogram
Resulting histogram
51
of
36
Histogram Equalization
Adjust 2 different images to make their histograms (intensity
distributions) similar
Apply a point operation that changes histogram of modified
image into uniform distribution
52
of
36
Linear Histogram Equalization
Histogram cannot be made exactly flat – peaks cannot be
increased or decreased by point operations.
Following point operation makes histogram as flat as
possible:
(assuming M x N image and pixels in range [0, K ‐ 1])
53
of
Effects of Linear Histogram
36
Equalization