Digital Image Processing - Lecture-5
Digital Image Processing - Lecture-5
By
Teams Link
https://teams.microsoft.com/l/team/19%3aV89kJ8amsbE3ssF9V0x
mGOukoYKvZIwPVey1-
EUiL4Y1%40thread.tacv2/conversations?groupId=47e1fe88-6e6b-
433e-b771-94c21eeb96c6&tenantId=ff4a48d6-4b5e-4fd3-8266-
7eafc3e6e23e
Text Book
R. Gonzalez, R. Woods.
Digital Ιmage Processing,
Prentice Hall, 2008.
Third Edition .
Histogram Processing
There are two Methods of Enhancing
Contrast:
1. The first one is called Histogram
Stretching that increase contrast.
2. The second one is called Histogram
Equalization that improve contrast.
3. The third one is called Histogram
(Specification) Matching that
improve contrast.
Histogram Processing
Histogram
h(rk ) nk
– where rk is the kth gray level and n k is the
number of pixels in the image having gray
level rk
– Normalized histogram
p(rk ) nk / n
Histogram Processing
Histogram equalization
s T (r ), 0 r 1
r T 1 ( s ), 0 s 1
Histogram Processing
Histogram Specification (HS)
Histogram Matching (Histogram Specification)
is the method used to generate a processed
image that has a specified histogram.
let 𝑝𝑟 (𝑟) and 𝑝𝑧 (𝑧) denote their corresponding
continuous probability density functions.
In this notation, 𝑟 and 𝑧 denote the gray levels
of the input and output images, respectively.
Histogram Matching
Histogram matching (specification)
r
s T (r ) ( L 1) pr ( w)dw
0
z
G ( z ) ( L 1) p z (t )dt s
0
z G 1 (s) G 1[T (r )]
k k nj
sk T (rk ) ( L 1) pr (rj ) ( L 1) , k 0,1,2,..., L 1
j 0 j 0 n
k
vk G ( zk ) ( L 1) p z ( zi ) sk , k 0,1,2,..., L 1
i 0
Histogram Matching
S-1*T
T S
Example
Suppose that a 3-bit image (𝑳=8) of size 64 × 64
pixels (𝑴𝑵 = 4096) has the intensity distribution
shown in following table, where the intensity
levels are integers in the range [0,𝐿 − 1] = [0, 7].
Example
Example
𝒔𝒌 𝑷𝒌 (𝒔𝒌 )
1 0.19
3 0.25
5 0.21
6 0.16+0.08
=0.24
7 0.06+0.03
+0.02
=0.11
Neighbourhood Processing
Spatial Filter
Spatial filtering is also called mask processing.
Using a filter kernel ( which is a sub-image,
w(x, y)) to operate on the image f(x,y).
Spatial filtering
1. Linear spatial filtering.
2. Nonlinear spatial filtering.
Linear Filter
If the function by which the new grey value is
calculated is a linear function of all the grey
values in the mask, then the filter is called a
linear filter.
A linear filter can be implemented by
multiplying all elements in the mask by
corresponding elements in the neighbourhood,
and adding up all these products.
corresponding pixels
Fundamentals of Spatial
Filtering
The Mechanics of Spatial Filtering
The process consists simply of moving the filter
mask from point to point in an image.
At each point (x,y) the response of the filter at
that point is calculated using
a b
g ( x, y ) w( s, t ) f ( x s, y t )
s at b
a=(m-1)/2 & b=(n-1)/2
The response R
R = w(-1, -1)f(x-1, y-1) +w(-
1,0) f(x-1, y)+….+w(0, 0)f(x,
y)+….+w(1,0)f(x+1, y)+
w(1,1)f(x+1, y+1)
Dr Mai Kamal DIP 2022 48
Fundamentals of Spatial
Filtering
Edges of the image
• Ignore the edges( The output image which is
smaller than the original).
• “Pad” with zeros( The output image of the same
size as the original).
Fundamentals of Spatial
Filtering
One important linear filter is to use a 3x3 mask and take
the average of all nine values within the mask. This
operation may be described as follows:
Averaging Filter
1 9
R zi
9 i 1
Weighted Averaging Filter
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s at b
a b
w(s, t )
s at b
Fundamentals of Spatial
Filtering
Example : Apply average filter on the following
image.
2 4 2
1 2 1
150.187 150.125
149.687 149.687
R w1 z1 w2 z2 ... w9 z9
9
wi zi
i 1
The mask 3x3
z z z
z z z Pixels behind the mask
3x3
z z z
Separable filters
Some filters can be implemented by the successive
application of two simpler filters.
The 3x3 averaging filter can be implemented by
first applying a 3x1averaging filter, and then
applying a 1x3 averaging filter to the result.
The 3x3 averaging filter is thus separable into two
smaller filters.
Separability can result in great time savings.
Suppose an nxn filter is separable into two filters
of size nx1 and 1xn.
Separable filters
Example
Median Filter:
fˆ ( x, y ) median{g ( s, t )}
( s ,t )S xy
Max Filter:
fˆ ( x, y ) max {g ( s, t )}
( s ,t )S xy
Min Filter:
fˆ ( x, y ) min {g ( s, t )}
( s ,t )S xy
Non-linear Filter
Linear filters are easy to describe, and can be
applied very quickly and efficiently by Matlab.
A non-linear filter is obtained by a non-linear
function of the greyscale values in the mask.
rank-order filters.
1. maximum filter
2. minimum filter
Median Filter
If the objective is to achieve noise reduction instead of
blurring, this method should be used.
This method is particularly effective when the noise
pattern consists of strong, spike-like components and
the characteristic to be preserved is edge sharpness.
It is a nonlinear operation.
Three steps to be followed to run a median filter:
1. Consider each pixel in the image.
2. Sort the neighboring pixels into order based upon
their intensities.
3. Replace the original value of the pixel with the median
value from the list.
Median Filter
Next Lecture
LEC.6: SPECIAL FILTER :
SHARPING