Lecture 5 and 6
Lecture 5 and 6
P(rk) = h(rk) / MN
Application
1. Image Enhancement
2. Image Thresholding
3. Image Segmentation
4. Image Analysis
2
Histogram Examples
3
Histogram Example
Histogram ? Intensity or Grey Level Frequency Normalized
Histogram
For a 3-bit image and size is 3x 3
1 3 3/9
1 2 6
2 1 1/9
6 1 3
3 1 1/9
1 6 6
6 4 4/9
4
Histogram Equalization
Its a technique used in image processing to improve the contrast of an image. It works by redistributing the intensity values
of the pixels in an image so that the histogram becomes more uniform.
Sk = T(rk)
Sk = L-1
Where –
L = number of possible intensity levels
Sk = output intensity levels
rk = input intensity levels
Why it is required ?
To enhance the contrast of an image, especially when the pixel intensity values are concentrated in a narrow range
(e.g., very dark or very bright images).
6
Histogram Equalization
7
Histogram Equalization Example
Consider a 3 bit image of size 64x64 (4096) with intensity distribution shown in the
below table. Calculate the Equalized histogram.
Sk = T(rk)
S = L-1x(Pk) = 7x0.19 = 1.33
Sk = L-1 8
Histogram Equalization Example
Consider a 3 bit image of size 64x64 with intensity distribution shown in the below
table. Calculate the Equalized histogram.
rk nk P(rk) Sk Approximate Value Updated nk Updated
of Sk P(rk)
0 790 0.19 1.33 1 790 790/4096
1 1023 0.25 3.08 3 1023
2 850 0.21 4.55 5 850
3 656 0.16 5.67 6 656+329 = 985
4 329 0.08 6.23 6
5 245 0.06 6.65 7 245+122+81= 448
6 122 0.03 6.86 7
7 81 0.02 7.00 7
Sk = T(rk)
Sk = L-1
9
Concept of Kernal or Filter or Convolution Mask
X1
W1
W1X1 + W2X2
W2
X2
10
Spatial Correlation and Convolution: Padding size (M-1)/2 or (N-1)/2
Input Image 0 0 0 0 0 0 0
0 0 0 0 0 Kernel
0 0 0 0 0 0 0
0 0 0 0 0 1 2 3 0 0 0 0 0 0 0
0 0 1 0 0 4 5 6 0 0 0 1 0 0 0
0 0 0 0 0 7 8 9 0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Correlation Convolution
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 9 8 7 0 0 0 0 1 2 3 0 0
0 0 6 5 4 0 0 0 0 4 5 6 0 0
0 0 3 2 1 0 0 0 0 7 8 9 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 11
Smoothing Spatial Filters
Smoothing Spatial Filter
Median Filters
Box Car or Mean
Filter
Max Filter
Weighted Avg.
Filter
Min Filter
Gaussian Filters
12
Image Smoothening: Box Car Filter
A filter that computes the average of pixels in the neighborhood blurs an image. Computing an average is analogous to
integration.
Or
A filter that reduces the sharp transition in the intensity called as smoothening or low pass filtering.
Convolving a smoothening kernel with image result in image blurring and the amount of blurring is always depends on
the size of the kernel.
Kernal Normalized Kernal
1 1 1 0.11 0.11 0.11
1/9 x 1 1 1 = 0.11 0.11 0.11
1 1 1 0.11 0.11 0.11
1 1 1 1
1 1 1 1
1/16 x
1 1 1 1
1 1 1 1 13
Image Smoothening: Box Car Filter
Comparison of outputs between Normalized and Non-Normalized Kernel
Image Normalized Kernel
1 2 3 0.11 0.11 0.11
4 5 6 0.11 0.11 0.11 0.11+0.22+0.33+0.44+0.55+0.66+0.77+0.88+0.99 = 4.95
7 8 9 0.11 0.11 0.11
14
Working Example: Padding size (M-1)/2 or (N-1)/2
Input Image
1 2 5 3 4 Kernel
5 6 7 8 9 0.11 0.11 0.11
2 3 4 5 6 0.11 0.11 0.11
3 6 8 4 2 0.11 0.11 0.11
1 5 6 8 7
1 2 1
1/16 x 2 4 2
1 2 1
15
Image Smoothening: Gaussian
Filter
16
Image Smoothening: Gaussian
Filter
Calculate the gaussian Kernel for 3x3 Kernel
Consider SD = 1
X=0,y=0 : SD =1 : 1/2pi =
17