0% found this document useful (0 votes)
13 views

Week 5

The document discusses image statistics and representation. It defines key terms like matrix representation of images, mean, variance, standard deviation, histograms, normalized histograms, contrast, and histogram equalization. Matrix representation shows an image as a 2D array of pixel intensities. Statistics like mean and variance are defined based on pixel intensities. Histograms count the number of pixels at each intensity level while normalized histograms show the proportion. Contrast and histogram equalization are techniques to improve image contrast and intensities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Week 5

The document discusses image statistics and representation. It defines key terms like matrix representation of images, mean, variance, standard deviation, histograms, normalized histograms, contrast, and histogram equalization. Matrix representation shows an image as a 2D array of pixel intensities. Statistics like mean and variance are defined based on pixel intensities. Histograms count the number of pixels at each intensity level while normalized histograms show the proportion. Contrast and histogram equalization are techniques to improve image contrast and intensities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Image Statistics

Digital Image Processing - 8th Semester - Week 5

Dr. Salman Ahmed

May 23, 2022


Image Statistics

Image Representation

Matrix representation
We are already familiar with matrix form representation of image as follows:
Image Statistics

Image Representation

Matrix representation

A(0, N − 1)
 
A(0, 0) A(0, 1) A(0, 2) ...
 A(1, 0)
 A(1, 1) A(1, 2) ... A(1, N − 1) 
 A(2, 0) A(2, 1) A(2, 2) ... A(2, N − 1) 
A =  A(3, 0)
 
 A(3, 1) A(3, 2) ... A(3, N − 1) 
 .. .. .. .. .. 
 . . . . . 
A(M − 1, 0) A(M − 1, 1) A(M − 1, 2) ... A(M − 1, N − 1)

The size of matrix A is M × N .


Image Statistics

Image Representation

Image statistics
The mean of an image, A, is denoted by mA and is expressed as follows:
PM −1 PN −1
i=0 j=0 A(i, j)
mA =
MN

2
The variance of image, A is denoted by σA and is expressed as follows:

PM −1 PN −1  2
i=0 j=0 A(i, j) − mA
2
σA =
MN

The standard
p deviation of image A is denoted by σA and is equal to
2
σA = σA
Image Statistics

Image Representation

Histogram
Histogram: An image histogram summarizes (or conveys information about)
the number of times an intensity level is used in an image.

Usually the histogram of an image is a graph/plot where on the x-axis we


have intensity levels, and on the y-axis we have the number of pixels for
corresponding (x-axis) intensity level.

For example: consider a 2-bits 4 × 4 image as follows:


Image Statistics

Image Representation

Histogram

Let us consider an image in the range [0, ..., L − 1]. We can represent
the image histogram as follows:

h(rk ) = nk

where
▶ rk = kth gray level or intensity level k
▶ nk = number of pixels in the image having intensity level k
▶ h(rk ) = histogram of image having rk intensity levels
Image Statistics

Image Representation

Histogram

From the previous slide, let us write again the histogram representation as
follows:
h(rk ) = nk

Normalized Histogram: If the total number of pixels is n, then the nor-


malized histogram is expressed as follows:
nk nk
p(rk ) = =
n MN
Image Statistics

Image Representation

Normalized Histogram
Let us re-visit our previous example again as follows:

Table: Histograms data

Intensity value, rk h(rk ) = nk p(rk )


5
0 5 16
4
1 4 16
1
2 1 16
6
3 6 16
Image Statistics

Image Representation

Normalized Histogram

In normalized histograms, the sum of all components is equal to 1


L−1
X
p(rk ) = 1
k=0
Image Statistics

Image Representation

Matlab Example
Image Statistics

Image Representation

Matlab Example
Image Statistics

Image Representation

Matlab Example
Image Statistics

Image Representation

Image statistics

Can we reconstruct an image from ’Histogram’ ?


Image Statistics

Image Representation

Image statistics
Can we reconstruct an image from ’Histogram’ ?

The answer is ’No’ because:


1. Histogram only contains statistical data about intensities with no
information about pixel location.
2. Histogram of an image is not unique. Different images can have the
same histogram.

Both the images will have same histogram because both images have only
two intensity values, spread over the whole image equally.
Image Statistics

Image Representation

Contrast

Image Contrast:
Image contrast is the difference between the highest and lowest intensity in
the image. We can differentiate images on the basis of contrast in them.

Low Contrast: Those images that look soft and the range of intensity in
their histogram is only in the middle, then such images are said to be low
contrast images.

High Contrast: High contrast images are sharp or crisp and have intensity
values at darkest and lightest areas.
Image Statistics

Image Representation

Image Contrast
Image Statistics

Image Representation

Image Contrast
Contrast stretching: In contrast stretching, the range of intensity values
of input image are spanned over the desired intensity range.
In the image the intensity values are spanned over full range of possible
intensity values.
Image Statistics

Image Representation

Image Contrast
Consider an image whose intensity range is from rmin to rmax and we
have to stretch this range over 0 to 255.

To perform this transformation we will use the formula:


L−1
s = T (r) = (r − rmin )[ rmax −rmin
]
Image Statistics

Image Representation

Histogram Equalization
In histogram equalization, histogram is spread and flatten.
Image Statistics

Image Representation

Histogram Equalization

The histogram equalization transform can be found by applying following


steps:
Steps of Histogram Equalization:
1. Find the running sum of the histogram values
2. Normalize the values from step-1 by dividing it by total number of
pixels and then multiplying it with maximum intensity value.
3. Round the value.
4. Map the intensity values to the results from step-3.
Image Statistics

Image Representation

Example of Histogram Equalization


Consider a 4-bit 128 × 128 image whose histogram is as follows:

Table: Example of Histogram equalization


Intensity value, rk nk
0 2015
1 2025
2 2200
3 2200
4 2000
5 2078
6 2250
7 1500
8 1
9 12
10 0
11 13
12 45
13 20
14 15
15 10
Image Statistics

Image Representation

Example of Histogram Equalization


Pk
Table: Step 1 - Running sum calculation uk = j=0 nj

Intensity value, rk nk uk
0 2015 2015
1 2025 4040
2 2200 6240
3 2200 8440
4 2000 10440
5 2078 12518
6 2250 14768
7 1500 16268
8 1 16269
9 12 16281
10 0 16281
11 13 16294
12 45 16339
13 20 16359
14 15 16374
15 10 16384
Image Statistics

Image Representation

Example of Histogram Equalization


uk ×(L−1)
Table: Step 2 - Partial values of transformed intensity value s´k = MN

Intensity value, rk nk uk s´k


0 2015 2015 1.84
1 2025 4040 3.69
2 2200 6240 5.71
3 2200 8440 7.72
4 2000 10440 9.55
5 2078 12518 11.46
6 2250 14768 13.52
7 1500 16268 14.89
8 1 16269 14.89
9 12 16281 14.90
10 0 16281 14.90
11 13 16294 14.91
12 45 16339 14.95
13 20 16359 14.97
14 15 16374 14.99
15 10 16384 15
Image Statistics

Image Representation

Example of Histogram Equalization


Table: Step 3 - Rounding the transformed intensity values of sk = round(s´k )
Intensity value, rk nk uk s´k sk
0 2015 2015 1.84 2
1 2025 4040 3.69 4
2 2200 6240 5.71 6
3 2200 8440 7.72 8
4 2000 10440 9.55 10
5 2078 12518 11.46 11
6 2250 14768 13.52 14
7 1500 16268 14.89 15
8 1 16269 14.89 15
9 12 16281 14.90 15
10 0 16281 14.90 15
11 13 16294 14.91 15
12 45 16339 14.95 15
13 20 16359 14.97 15
14 15 16374 14.99 15
15 10 16384 15 15
Image Statistics

Image Representation

Example of Histogram Equalization

Table: Step 4 - Transformed Intensity Values

Transformed intensity, sk nk
2 2015
4 2025
6 2200
8 2200
10 2000
11 2078
14 2250
15 1500 + 1 + 12 + 0 + 13 + 45 + 20 + 15 + 10=1616
Image Statistics

Image Representation

Example of Histogram Equalization

Figure: Histogram Equalization


Image Statistics

Image Representation

Histogram Equalization Formula

Considering the histogram equalization steps, we can write the following


equation for histogram equalization
k
(L − 1) X
sk = nj
M ×N j=0

where,
sk = Transformed intensity
nj = Frequency of intensity j
Image Statistics

Image Representation

Matlab Example
Image Statistics

Image Representation

Histogram

Histogram doesn’t ALWAYS give desirable results


Image Statistics

Image Representation

Example
Image Statistics

Image Representation

Solution

We can specify the final histogram.


For that we will need two histograms i.e.
1. Histogram of input image
2. Target Histogram
From these histograms we will estimate the transformation
z = T (r)
And this process is known as Histogram Specification or Histogram
Matching
Image Statistics

Image Representation

Histogram Specification
Image Statistics

Image Representation

Histogram Specification
Step 1:
Get the target histogram and input image histogram.

Step 2:
Equalize the histogram of input image and target image.

k
X
sk = T (rk ) = (L − 1) pr (rj )
j=0

q
X
sk = G(zq ) = (L − 1) pz (zi )
i=0
Image Statistics

Image Representation

Histogram Specification

As left hand side is same, Thus


G(z)=T(r)
We have to obtain zq
Taking Inverse Transform
zq = G−1 (T (rk ))
The above formula will give histogram specification.
Image Statistics

Image Representation

Example
Consider a 3-bit 64×64 input image and a 3-bit 4×7 image whose his-
togram is used as target histogram.
Image Statistics

Image Representation

Example

Step 1: Equalizing input and target histograms .


Image Statistics

Image Representation

Example
Image Statistics

Image Representation

Example
After both images have been equalized, we have to perform inverse map-
ping.
1. For each value in the round column of original image, find the corre-
sponding value in the round column of the target image and note its index.
2. If the value doesn’t exist in the round column of the target image, find
the index of the nearest value.
3. If multiple nearest values exist in the round column of the target image,
choose the index that is greater than the value.
Image Statistics

Image Representation

Example
Image Statistics

Image Representation

Example

You might also like