Digital Image
• It is a matrix of size MxN
• Operations
– To make image look better: Enhancement
• Enhancement
– Spatial processing
– Intensity processing
8/10/2025 1
Probability – PMF
Calculating PMF from image matrix
PMF
Image matrix
0 2 2/25
1 2 7 5 6 1 4 4/25
7 2 3 4 5 2 3 3/25
0 1 5 7 3
3 3 3/25
1 2 5 6 7
6 1 0 3 4 4 2 2/25
5 4 4/25
6 3 3/25
7 4 4/25
Histogram
• Histogram is a graph that shows frequency
of anything. Histograms usually have bars
that represent frequency of occuring of
data.
• Histogram has two axis: x and y.
• The x axis contains the event whose
frequency we count.
• The y axis contains frequency.
Histogram
• Consider some students with their marks.
Histogram Equalization
The intensity levels in an image may be viewed as
random variables in the interval [0, L-1].
Let pr (r ) and ps ( s ) denote the probability density
function (PDF) of random variables r and s.
8/10/2025 5
Histogram Equalization
s = T (r ) 0 r L −1
a. T(r) is a strictly monotonically increasing function
in the interval 0 r L -1;
b. 0 T (r ) L -1 for 0 r L -1.
8/10/2025 6
Histogram Equalization
s = T (r ) 0 r L −1
a. T(r) is a strictly monotonically increasing function
in the interval 0 r L -1;
b. 0 T (r ) L -1 for 0 r L -1.
T (r ) is continuous and differentiable.
ps ( s)ds = pr (r )dr
8/10/2025 7
Histogram Equalization
r
s = T (r ) = ( L − 1) pr ( w)dw
0
ds dT (r ) d r
dr
=
dr
= ( L − 1)
dr 0
pr ( w) dw
= ( L − 1) pr (r )
pr (r )dr pr (r ) pr (r ) 1
ps ( s ) = = = =
ds ds ( ( L − 1) pr (r ) ) L − 1
dr
8/10/2025 8
Example
Suppose that the (continuous) intensity values
in an image have the PDF
2r
, for 0 r L-1
pr (r ) = ( L − 1) 2
0, otherwise
Find the transformation function for equalizing
the image histogram.
8/10/2025 9
Example
r
s = T (r ) = ( L − 1) pr ( w)dw
0
r 2w
= ( L − 1) dw
0 ( L − 1) 2
2
r
=
L −1
8/10/2025 10
Histogram Equalization
Continuous case:
r
s = T (r ) = ( L − 1) pr ( w)dw
0
Discrete values:
k
sk = T (rk ) = ( L − 1) pr (rj )
j =0
k nj L −1 k
= ( L − 1) = nj k=0,1,..., L-1
j = 0 MN MN j =0
8/10/2025 11
Example: Histogram Equalization
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096)
has the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the
ps(sk) for each sk.
8/10/2025 12
Example: Histogram Equalization
0
s0 = T (r0 ) = 7 pr (rj ) = 7 0.19 = 1.33 →1
j =0
1
s1 = T (r1 ) = 7 pr (rj ) = 7 (0.19 + 0.25) = 3.08 →3
j =0
s2 = 4.55 → 5 s3 = 5.67 → 6
s4 = 6.23 → 6 s5 = 6.65 → 7
s6 = 6.86 → 7 s7 = 7.00 → 7
8/10/2025 13
Example: Histogram Equalization
8/10/2025 14
8/10/2025 15
8/10/2025 16
Histogram equalization
• Histogram equalization is used for enhancing
the contrast of the images.
• The first two steps are calculating the PDF
and CDF.
• All pixel values of the image will be
equalized.
Histogram equalization
• Image with its histogram
Histogram equalization
Small image Small image
(values) (values)
Histogram equalization
Image detail
Frequency of pixel values
Histogram equalization
Histogram equalization
• min = 52
• max = 154
cdfmin is the minimum non-zero value of the cumulative distribution function (in
this case 1), M × N gives the image's number of pixels (for the example above
64, where M is width and N the height) and L is the number of grey levels used
(in most cases, like this one, 256).
Histogram equalization
New min. value = 0, old min. value 52
New max. value = 255, old max. value 154
Original Equalized
Histogram equalization
An unequalized image Corresponding histogram (red)
and cumulative histogram (black)
The same image after Corresponding histogram (red)
histogram equalization and cumulative histogram (black)
Corresponding
Histograms
Source image
Histogram Matching
Histogram matching (histogram specification)
— generate a processed image that has a specified histogram
Let pr ( r ) and pz ( z ) denote the continous probability
density functions of the variables r and z. pz ( z ) is the
specified probability density function.
Let s be the random variable with the probability
r
s = T (r ) = ( L − 1) pr ( w)dw
0
Define a random variable z with the probability
z
G ( z ) = ( L − 1) pz (t )dt = s
0
8/10/2025 26
Histogram Matching
r
s = T (r ) = ( L − 1) pr ( w)dw
0
z
G ( z ) = ( L − 1) pz (t )dt = s
0
−1
z = G ( s) = G −1
T (r )
8/10/2025 27
Histogram Matching: Procedure
• Obtain pr(r) from the input image and then obtain the values of s
r
s = ( L − 1) pr ( w)dw
0
• Use the specified PDF and obtain the transformation function G(z)
z
G ( z ) = ( L − 1) pz (t )dt = s
0
• Mapping from s to z
z = G −1 ( s)
8/10/2025 28
Histogram Matching: Example
Assuming continuous intensity values, suppose that an image has
the intensity PDF
2r
, for 0 r L -1
pr (r ) = ( L − 1) 2
0, otherwise
Find the transformation function that will produce an image whose
intensity PDF is
3z 2
, for 0 z ( L -1)
pz ( z ) = ( L − 1) 3
0, otherwise
8/10/2025 29
Histogram Matching: Example
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
Find the histogram equalization transformation for the specified histogram
z z 3t 2 z3
G ( z ) = ( L − 1) pz (t )dt = ( L − 1) dt = =s
0 0 ( L − 1) 3
( L − 1) 2
The transformation function
1/3
1/3 2 r
2
2 1/3
z = ( L − 1) s
2
= ( L − 1) = ( L − 1)r
L − 1
8/10/2025 30
Histogram Matching: Discrete Cases
• Obtain pr(rj) from the input image and then obtain the values of sk,
round the value to the integer range [0, L-1].
k
( L − 1) k
sk = T (rk ) = ( L − 1) pr (rj ) = nj
j =0 MN j =0
• Use the specified PDF and obtain the transformation function
G(zq), round the value to the integer range [0, L-1].
q
G ( zq ) = ( L − 1) pz ( zi ) = sk
i =0
• Mapping from sk to zq
zq = G −1 ( sk )
8/10/2025 31
Example: Histogram Matching
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096)
has the intensity distribution shown in the following table (on the
left). Get the histogram transformation function and make the output
image with the specified histogram, listed in the table on the right.
8/10/2025 32
Example: Histogram Matching
Obtain the scaled histogram-equalized values,
s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 7,
s5 = 7, s6 = 7, s7 = 7.
Compute all the values of the transformation function G,
0
G ( z0 ) = 7 pz ( z j ) = 0.00 →0
j =0
G ( z1 ) = 0.00 →0 G ( z2 ) = 0.00 → 0
G ( z3 ) = 1.05 →1 G ( z4 ) = 2.45 → 2
G ( z5 ) = 4.55 → 5 G ( z6 ) = 5.95 → 6
G ( z7 ) = 7.00 → 7
8/10/2025 33
Example: Histogram Matching
8/10/2025 34
Example: Histogram Matching
Obtain the scaled histogram-equalized values,
s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 7,
s5 = 7, s6 = 7, s7 = 7.
Compute all the values of the transformation function G,
0
G ( z0 ) = 7 pz ( z j ) = 0.00 →0
j =0
G ( z1 ) = 0.00 →0 G ( z2 ) = 0.00 → 0
G ( z3 ) = 1.05 → 1 s0 G ( z4 ) = 2.45 → 2 s1
G ( z5 ) = 4.55 → 5 s2 G ( z6 ) = 5.95 → 6 s3
G ( z7 ) = 7.00 → 7 s4 s5 s6 s7
8/10/2025 35
Example: Histogram Matching
s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 7,
s5 = 7, s6 = 7, s7 = 7.
rk
0
1
2
3
4
5
8/10/2025 6 36
7
Example: Histogram Matching
rk → zq
0→3
1→ 4
2→5
3→6
4→7
5→7
6→7
7→7
8/10/2025 37
Example: Histogram Matching
8/10/2025 38
Example: Histogram Matching
8/10/2025 39
Example: Histogram Matching
8/10/2025 40