Академический Документы
Профессиональный Документы
Культура Документы
Chapter 04
12/ 2010 1c). Differentiate between Spatial Resolution and Tonal resolution
12/ 2010 3b) Given an image of size (3 x 3)
f (m, n) =
0
100
1
90
2
85
3
70
4
0
5
0
6
0
7
0
Perform histogram stretching so that new image has a dynamic range of [0, 7]
2
(10)
2). Distinguish the point operations and Spatial operations in the Spatial- domain
processing for image enhancement
(5)
3). State whether the following statements are true or false. Briefly explain
the reason for your contention:
a. The principal function of median filter is to force points with distinct intensities
to be more like their neighbours.
(5)
b. Median filter is the best solution to remove salt and pepper noise.
(5)
(5)
3
5. State and explain the point operations in spatial domain for image enhancement
giving at least one application each case.
(10)
6. Equalize the following histogram:Grey level r
0
1
2
No. of pixels
790
1023
850
3
656
4
329
5
245
6
122
7
81
Y coordinate, 0 to N-1
X
coordinate
0 to M-1
- Image starts from left top corner (Scanning left to right and top to bottom)
- Values of gray scale at any coordinate (x, y) is f( x, y) :
y
f(0,0), f(0,1), f(0,2) ---- --
f(0, N-1)
f(M-1, N-1)
11
12
14
15
1. Point Processing
When the sub-image size is taken as 1x 1 ( single pixel)
thus processing is carried out on single pixel at a time
- Enhancement at any point (new pixel value) in an image depends only
on the original grey level value at that point
(Not on the neighborhood pixels)
16
or
- Linear
Negative and
Identity transformations
- Logarithmic
- Power law
nth
s=r
is a trivial case
(output pixel = input pixel)
17
(Digital negative)
19
Transformation T
125
10
0
10
125
255
original grey level r (input)
In identity transform
The image is not modified
The new image is having same grey levels as the original image
20
1. Image Negative :
- Produces equivalent of photographic negative
- image gray level at any pixel
s = (L-1) r
Gray levels range from 0 to L-1 and
r (pixel value before processing)
`
s = rmax r
= 255 r
245
Transformation T
125
S = 255 r
10 10
0
0 10
125
245 255
original grey level r
rmax = 255
S = 255 245 = 10
21
22
<m=0
Two levels
23
Contrast stretching:
(Piecewise linear transformation)
- The advantage of this transform is that the form of
the piecewise function can be arbitrarily complex
- It increases the contrast of the image by making
the dark portion, darker and
the bright portion, brighter
Low contrast image may be due to
- Poor illumination
- Lack of dynamic range of sensors
- Wrong setting of aperture / lens
- Contrast stretching expands the range of intensity levels in
an image, so that it spans the full intensity range of
recoding medium or display device
(Example 100 to 150 to 50 to 200)
- This transformation increases the dynamic range of an image
24
- If r1 = r2
Identity
transformation
25
Low contrast
Image
Image after
contrast stretching
26
3. Thresholding
Extreme contrast stretching yields thresholding
If in the contrast stretching diagram:
the first and the last slope is made zero, and
the center slope is made maximum
i.e. r1 = r2 and s1 = 0 and s2 = L-1
s = 0 ; if r < a
s = L-1; if r > a
where L is the maximum number of grey levels
a is threshold
L-1
Modified
grey level
s
0
0
s = T( r )
a
L-1
Original grey level r
27
Low contrast
Image
Thresholding
28
s = c log ( 1+ r)
Where c is a constant,
r is the original pixel value
- Widens the range of the lower-levels values
(dark pixels) in the input image
- Compress the range the higher-level values
(light pixels) in the input image
- Compresses dynamic range of pixels
( which sometimes becomes very large after
processing, i. e. in Fourier spectrum)
- Scales down the large range of levels to 0 to 255
from very large values
( Fourier spectrum range 0 to 10 6)
29
30
Fourier Spectrum
with range = 0 to
1.5 x 106
correction:
If is < 1
If is > 1
0<<1
<1
L/2
>1
L/16
>1
33
Gamma correction
Chapter 3
Image Enhancement in the
Spatial Domain
C=1
34
35
C= 1
Gamma = 0.6
C= 1
Gamma = 0.4
C= 1
Gamma = 0.3
36
37
High
Low
Original image
39
High
41
Bit plane 8
(Most significant, bit- 7)
Bit plane 1
(Least significant, bit-0 )
42
Bit 7
Bit 5
Bit 2
Bit 4
Bit 1
Bit 6
Bit 3
Bit 0
43
44
45
-After the new value of a pixel at the center of the mask is calculated,
the mask is shifted by one step (pixel)
(From left to right and top to bottom)
-The operation is same as convolution of two signals,
One signal is flipped then moved across the other signal step by step
- Same thing is done in the neighborhood processing,
only the mask is not flipped as it is symmetrical
46
y -1
y+1
x -1
f (x , y-1) f (x , y ) f (x , y+1)
3 x3 neighborhood of (x, y)
x+1
x
w1
w4
w7
w2
w3
w5
w6
w8
w9
3 x 3 mask/ window or
a template
47
Frequencies in an image
- Just as in signals we have high frequencies and low frequencies,
we have frequencies in images
- High frequency in signals, means that the number of oscillations
of the signal per unit time are high.
- If the signal is voltage, the high frequency means that
the voltage is changing at a high rate
- In images the rate of change of grey levels relates to frequency
If an image has only one grey level, the change of grey level
across the image is zero
thus the frequency is zero (DC)
At edges in an image,
the rate of change of grey levels is high,
thus the edge represent high frequency regions
48
49
NOISE:
- The principle source of noise in a digital images arise during acquisition
and transmission of images.
-Based on the shapes of the noise (Probability Density Functions),
the noises are classified as:
1. Gaussian Noise
2. Salt-and-Pepper noise /
Impulse noise / Speckle Noise
3. Rayleigh Noise
4. Gamma Noise
5. Exponential Noise
6. Uniform Noise.
The first two, Gaussian and Salt-and-pepper noise are more common
50
Gaussian noise
It is statistical noise that has its probability density function
equal to that of the normal distribution,
which is also known as the Gaussian distribution
p (z) =
(z - )2 / 2 2
1. e
---------------------- 2
Where
z is grey level
is Mean of average value of z
is Standard deviation
2 is Variance
1/ 2
0.67/ 2
-
Grey level
51
Salt-and-Pepper Noise
PDF of the salt and pepper noise (bipolar noise) is
Pa ;
for z =a
p (z)
Pb ;
for z = b
0;
otherwise
Generally a and b are black and white grey levels, respectively
(for a 8-bit image a =0 and b = 255)
(white is salt noise and black is pepper noise)
Pb
Pa
a
Grey level
52
Spatial filtering
- Filtering in terms of signal frequencies,
refers to accepting ( passing) or rejecting certain
frequency components
Lowpass filter: passes low frequencies (rejects high frequencies)
Highpass filter: passes high frequencies (rejects low frequencies)
- Filtering effect on images can be achieved by spatial filters
also called spatial mask, kernels, templates or windows
- Filtering operations, that are performed directly on the pixels of
an image are called SPATIAL FILTERING.
53
54
55
56
0, 0
Image f (x, y)
W = weightage
w ( 0, -1)
w ( 0, 0)
w ( 1, -1)
w ( 1, 0)
w ( -1, 1)
w ( 1, 1)
x, y
x, y
=MxN
x = 0 , 1, 2, 3 - - - -y = 0 , 1, 2, 3 - - - --
Filter mask
=mxn
a = (m-1)/ 2
M-1
N-1
b = (n-1)/2
s = + a t = -b
g ( x, y) =
w (s, t ) . f{ ( x + s), (y + t )}
s = - a t = -b
x = 0, 1, 2 - - - - - M-1
y = 0,1, 2, 3 - - - - - N-1
It is also called Convolution Mask
as linear filtering is similar to convolution in frequency domain
Response R = w 1 z 1 + w 2 z 2 + -------------------- w m n . z m n
Where ws are the coefficients of an m x n filter
and zs are the corresponding image intensities
of pixels of the image encompassed by filter
i= m.n
R
=
w i . zi
i=1
= w i . zi
58
w1
w2
w4
w5
w6
z4
z5
z6
w7
w8
w9
z7
z8
z9
w kzk
k=1
Where w and z are 9 dimensional vectors
At boundary of an image
1. Simplest solution:
- Dont take mask to border pixels,
limit center to (n-1) / 2 pixel away
- The resultant image will be smaller than original
2. Padding of image by rows and columns by:
a)
0 value,
b)
Some other constant value or
c)
Replicate the last columns and rows
59
61
i=9
R = 1/9 x z i
i=1
Spatial average filter with all coefficients are equal is also called
Box filter
1 1 1
1/ 9 x
1 1 1
1 1 1
(9 is sum of all values of all 9 coefficients for finding average)
For 5 x5 mask, the multiplying factor will be 1/25 ?
9
In term of general formula R =
w kzk
k=1
The mask will be
62
0 1 0
1 2 1
0 1 0
1/10 x
1 1 1
1 2 1
1 1 1
63
Average
filter size
3x3
Average
filter size
5x5
15 x 15
9x9
35 x 35
Processed Image
Average filter
15 x15
Threshold image
with 25 % of
the highest intensity
65
Min filter
f ( x, y ) median{g ( s, t )}
( s ,t )S xy
67
68
Median value
in 3 x3 neighborhood, the 5th largest value is the median
in 5 x5 neighborhood, the 13th largest value is the median
Example: Neighborhood values in 3 x3 mask:
{10, 20, 20, 20, 15, 20, 20, 25, 100}
10 20 20
20 15 20
20 25 100
Sorted values: {10, 15, 20, 20, 20, 20, 20, 25, 100}
The median is 5th value = 20
20 will replace center pixel 15
- Principal function of the median filter is
to make pixels with distinct intensity more like its neighbors
- Isolated light or dark cluster of pixels are eliminated
The clusters having the area less than (m x n) / 2
are eliminated. (1/2 of the area of the filter)
Where m x m is size of the mask69
Noise reduction by
3 x3 average filter
Noise reduction by
3 x3 Median filter
70
f ( x, y ) max {g ( s, t )}
( s ,t )S xy
71
f ( x, y ) min {g ( s, t )}
( s ,t )S xy
72
or
5, 6, 8, 0
1, 2 -8
= next pixel value current pixel value
5, 6, 8, 0
1, -10
75
76
Image
Ramp
Isolated point
Thin line
Step
77
f (x + 1 ) f (x)
f( x +1) + f (x-1)
2 . f (x)
78
Comparing the response between the first- and second order derivatives :
- The first order derivatives:
- Generally produce thicker edges in an image.
- Generally have a stronger response to a gray level step
- Are used basically for edge extraction.
- The second order derivatives:
- Have a stronger response to fine details
such as thin lines and isolated points.
- Produces a double response at step changes in gray level.
- Are better than first order derivatives
because of their much better ability to enhance fine detail
- Are easier to implement and also enhances the fine details much better
Thus only the second order derivatives are considered for high-pass filtering
79
Using the second order derivative for image sharpening The Laplacian
- The filter should be an isotropic filter for image sharpening
so that the response of the filter is
independent of the direction of the discontinuities
in the image
- The isotropic filters are rotation invariant:
- Rotating the image and then applying the filter
should gives same results as
- Applying the filter first to the image and then rotating the result
Simplest isotropic derivative operator is Laplacian
Laplacian for an image f (x, y), of two variables is defined as:
2 f = 2f/ x2 + 2 f / y 2
, inverted delta , represents differentiation
80
0 -1 0
and
-1 -1 -1
-1 4 -1
-1 8 -1
0 -1 0
-1 -1 -1
- These are obtained from definitions of the derivatives that are negative
of the one used earlier,
- They yield equivalent results, but the difference in sign must be kept in mind
82
while combining Laplacian-filtered image with another image
83
The basic way the Lapalician is used for image sharpening is:
g ( x, y) = f (x, y) + c . [
f (x, y) ]
where c is a constant
c = -1 if the Laplacian filter
with - 4, or -8 at the center are used
Otherwise c = +1 for the other two filters with +4 and +8 at the center
84
Scaling
Laplacian contains both positive and negative values
- Negative values can be set to zero for display, thus
result will be mostly black
- Better method is to scale Laplacian
by adding to the min value to the all pixels of the image
to bring the minimum value of pixels to zero
then scale to all the 255 levels by
multiplying with 255 / maximum value of the
pixels in the image
- After scaling the result will be having mostly grey background
85
Blurred image of
the moon
86
Laplacian Image,
scaled for display
Background Is grey
Laplacian image
Enhanced by adding/ subtracting
from the original image
87
88
f ( x, y)
89
Original signal
Blurred signal
with original signal
shown dashed
Unsharp mask
Sharpened signal
Obtained by adding
original
to the Unsharp Mask
90
Original image
Result of blurring
with a Gaussian filter
Unsharp Mask
Result of using
Unsharp mask (k = 1)
Result of using
Highboost filtering
K>1
91
Original image
93
94
Using the first order derivative for (non-linear) image Sharpening Gradient
Let in a 3x3 region of an image
zs be grey level values/ intensities
as shown
x-1, y-1
x-1, y
x-1, y+1
f (x, y)
X+1, y-1
x+1, y
x+1, y+1
95
96
Sobel operators
For gradient in x and y direction
97
Histogram Modelling
- Histogram of images provide a global description of
the appearance of an image
- By definition, histogram of an image represents
the relative frequency of occurrences of
the various grey levels in the image.
- Histogram can be plotted in two ways:
nk
p ( rk)
= n k/ n
98
Method 1:
Grey level
Number of
pixels nk
40
20
10
15
10
40
Number
Of pixels 30
nk
20
20
10
10
15
10
3
0
0
2
6 Grey level
99
Method 2:
- In this method in place of the number pixels,
the probability is plotted
Probability
Grey level
Number of
pixels nk
Probability
p (rk)
p (rk ) = nk / n
40
20
10
15
10
0.4
0.2
0.1
0.15
0.1
0.03
0.02
n =100
0.4
0.3
0.2
0.15
p (rk) 0.2
0.1
0.1
0.1
0.0
0
0.03
0.02
100
6 Grey level
Normalized Histogram:
- Normalized Histogram
It is plot of probability of pixel p (rk) vs grey levels r
Probability of pixel, being grey level rk :
p (r k) = n k / n
102
255
Gray levels
Complete white image
Number
at any
pixel
value
Gray levels
Darker image
Number
at any
pixel
value
Gray levels
Complete Black image
Number
at any
pixel
value
Gray levels
Brighter image
1. Software or
2. Hardware
103
Dark image
Bright image
An image whose pixels tend to occupy the entire range of grey levels
tend to distribute uniformly will have
and
and
105
Histogram Stretching:
- Used for increasing the dynamic range of image.
- The shape of image is not altered but
the image is spread so as
to cover the entire dynamic range
smax
smin
rmax
rsmin
(smax. smin )
( rmax rmin)
x (r rmin) + smin
106
Linear streching
s
smax
smin
S= T(r)=
rmin
smax. smin
rmax rmin
rmax
x ( r rmin)
r
+ smin
for every
Grey level
0
1
2
3
4
5
6
7
No. of pixels
100
90
85
70
0
0
0
0
Perform histogram stretching so that new image has a dynamic range of [0, 7]
rmin = 0, rmax = 3
x (r rmin ) + smin
s = (7 -0)/ (3-0) x ( r 0) + 0
Thus for r=0
r=1
r=2
r=3
So
r
0
1
2
3
= 7/3 x r
s = 7/3 x 0
s = 7/3 x 1
s = 7/3 x 2
s = 7/3 x 3
s
0
2
5
7
pixels
100
90
85
70
Stretched histogram
=0
= 7/3 = 2.3
= 14/3 = 4.6
= 21/3 = 7
=0
2
5
=7
nk
100
90
85
70
108
As perfect image is one which has equal number of pixels at all its
grey levels.
Thus to get a perfect image, the objective are:
1. To spread the dynamic range and also
2. To have equal pixels at all the grey levels.
This technique is known as HISTOGRAM EQUALIZATION
.
109
Histogram Equalization:
-The histogram of low-contrast image is narrow
- if the histogram is distributed to a wider range the quality of the image
will be improved.
This can be achieved by adjusting the probability density function of the
original histogram of the image
so that the probability of grey levels occurring spreads equally.
Histogram equalization spreads dynamic range and
generates an image with
equal number of pixels in all the grey levels
110
Histogram equalization:
- In Linear stretching, histogram stretches,
but the shape remains same
Histogram equalization
- Histogram spreads to all levels and also become flat
(Equal number of pixels at all levels)
nk
Linear stretch
r
nk
nk
Histogram equalized
111
Histogram equalization
- The objective is to find a transformation which would
transform a bad histogram to an Equalized histogram
We know that
s = T (r )
Where s is the output
T is transform
r is gray level of input image with range 0 to 1,
level
r = 0 is black
level
r = 1
is white
thus any level r lies between 0 and 1
Let s be equalized histogram = T (r )
where the range grey level r is between 0 and 1
s1
r1
r2
113
T (r )
s2
s1
r1
r2
114
0 s1
115
Condition a :
Single-valued (one-to-one relationship) guarantees
that the inverse transformation exists.
Monotonicity condition preserves
the increasing order from black to white in the output image
.
Condition b
0 T( r ) 1 for 0 r 1
guarantees that the output gray levels are in
the same range as the input levels.
Therefore the inverse transformation from s back to r exits and it is
r = T -1 ( s )
where 0 s 1
The grey levels for continuous variables ( r and s )can be characterized by
their Probability Density Function (PDF) ( p r ( r ) and p s ( s ) )
Any intensity level in an image may be viewed as random variables
in the interval [0,1].)
116
[ p r ( r ) . dr / ds ] r = T
-1
(s )
.1
0r1
ps(s)=
[ p r ( r ) . dr / ds ]
ps( s ) = pr ( r ) / pr (r ) = 1
Which is nothing but the UDF (Uniform Density Function)
118
UDF
ps( s )
1
s
1
Thus, we get
ps(s)
pr(r)
1
Cumulative
density
function
pr ( r ) dr
119
k
= .
pr (r j )
j =0
k
= n j / n
j=0
k = 0, 1, 2
(L-1)
Map each pixel with level r k into corresponding pixel with level s k
p r (r k) versus r k
( from original histogram)
S k gives linearized or equalized of histogram
s k = new value of gray level for the grey level (r k ) in original image
k
= p r (r j )
(Cumulative Density Function)
j=0
k = 0, 1, 2 to L-1
121
New value of level sk , for the original level r k in the original image
s k = T (r k)
for r 0, r 1, r 2
k
( pr (r j) )
j=0
r L-1
k
= (n j /n)
j= 0
= n0/n + n1/ n - Thus
s0 =
s1 =
s2 =
.
.
sk =
n k /n
up to k
p r (r 0)
= n 0/n
p r (r 0) + p r (r 1)
= n00/n + n1/n
p r (r 0) + p r (r 1) + p r (r 2) = n0/n + n1/n + n2 /n
p r (r 0) + p r (r 1) + p r (r 2)
up to L-1 as k = L-1
---- + p r (r k)
k = 0, 1, 2 . . L-1
j = 0 to 0 as k = 0
j = 0 to 1 as k = 1
j = 0 to 2 as k = 2
j = 0 to k as k = k
122
Grey
Level
0
1
2
3
4
5
6
7
nk
790
1023
850
656
329
245
122
81
n= 4096
2
850
3
656
PDF
pr (rk)
= nk / n
CDF
sk =
pr(rk)
(L-1) x sk
= 7 x sk
0.19
0.25
0.21
0.16
0.08
0.06
0.03
0.02
0.19
0.44
0.65
0.81
0.89
0.95
0.98
1
1.33
3.08
4.55
5.67
6.23
6.65
6.86
7
4
329
5
245
6
122
7
81
Rounding off
1
3
5
6
6
7
7
7
123
nk
790
1023
850
656
329
245
122
81
Equalized
grey
level
0
1
2
3
4
5
6
7
2nd
New
grey
level
1
3
5
6
6
7
7
7
Number
of
pixels
0
790
0
1023
0
850
985
(656 + 329)
448
(245+ 122 + 81)
Equalized histogram
New grey level vs total pixel at that level
nk
1023
1023
850
790
Original histogram
656 (old grey level vs pixels)
329
790
448
= 245
+ 122
+ 81
245
122
81
0
985
=656
850
+329
7b
124
Original images
Dark
Bright
Low
Contrast
High
Contrast
125
126
Inverse Transfer
rk = T-1 (sk)
where k =0,1,2,3,
--- L-1
(Reverse transform satisfies conditions a and b,
if none of the level is missing)
[a, single valued and monotononically increasing
b The range of s, same as r , 0 to 1 ]
Using the inverse transform we can get back the original histogram
pr (r)
Suppose
127
128
2
850
3
656
4
329
5
245
6
122
7
81
2
0
3
614
4
819
5
1230
6
819
7
614
2
0
3
1023
4
0
5
850
6
985
7
448
1
0
1
790
129
0
1
2
3
4
5
6
7
nk
0
0
1
0
PDF
pr (rk)
2
0
CDF
sk =
= nk / N
3
614
(L-1) x sk
= 7 x sk
pr(rk)
4
819
5
1230
6
819
7
614
Rounding off
0
0.0
0.0
0.0
0
0.0
0.0
0.0
0
0.0
0.0
0.0
614
0.149 0.149 1.05
819
0.20
0.35
2.45
1230
0.30
0.65
4.55
819
0.20
0.85
5.97
614
0.15
1
7
N = 4096
From above the reverse level
1 3, 3 4, 5 5, 6 6, 7 7
mapping is:
0
0
0
1
3
5
6
7
130
5
850
6
985
5
850
6
985
7
448
7
Reverse mapping: 1 3, 3 4, 5 5, 6 6, 7 7
The final histogram
Grey level
0
No. of pixels
0
1
0
2
0
3
790
4
1023
7
448
985
1023
850
790
448
131
132
Original image
133
m =
L-1
r i
i =0
x p ( r i)
134
zero th movement
1 The First moment
L
Second moment 2 ( r ) =
( r i - m ) 2 x p ( r i)
i =0
The above expression is intensity variance of r
The standard deviation = variance
denoted by 2 ( r )
[f (x , y) m] 2
x=0 y=0
135
Original image
Dark portion on
right lower side
Image where
the contrast of only
the darker side of
the image is isolated
and contrast enhanced
136
END
137
138
Histogram processing
Enhancement using arithmetic/ logic operations
Image subtraction.
Image Averaging
139
ps(s)=
[ p r ( r ) . dr / ds ]
from equation 1
2.
k = 0, 1, 2, . . (L-1)
is histogram
k
nj
j=0
0
s0 = 7
pr (rj) = 7. pr (r0)
j=0
s1 = 7. prr(r0) + 7. pr (r1)
for L =8
141