Image Processing
Image Processing
s = T (r)
Contrast Thresholding
stretching
s=L-1-r
s = cr
s = r2.5
r = [1 10 20 30 40 210 220 230 240 250 255]
s( = 2.5) = [0 0 0 1 2 157 176 197 219 243 255]
s( =.4) = [28 70 92 108 122 236 240 245 249 253 255]
Dr. A. NAGARAJA RAO
Power-Law Transformations - Gamma Correction
c=1
= 0.4 c=1
= 0.3
Dr. A. NAGARAJA RAO
Power-Law Transformations
c=1
=3
c=1 c=1
=4 =5
• Advantage
• Arbitrarily complex
• Disadvantage
• More user input
• Type of Transformations
• Contrast stretching
• Gray-level slicing
• Bit-plane slicing
Contrast stretching:
(r1,s1)=(rmin,0) , (r2,s2)=(rmax,L-1)
Thresholding:
(r1,s1)=(k,0) , (r2,s2)=(k,L-1)
Exercise:
the following matrix represents the pixels values of a 8-bit image (r) , apply
thresholding transform assuming that the threshold m=95, find the resulting image
pixel values.
Image (r)
90 91 99 100
82 96 85 90
[10000000] [01000000]
[00100000] [00001000]
[00000100] [00000001]
Histogram
The histogram of a digital image with gray levels in
the range [0, L-1] is a discrete function
h(rk) = nk,
where rk is the kth gray level and nk is the number of
pixels in the image having gray level rk.
Normalized Histogram
Dividing each value of the histogram by the total number
of pixels in the image, denoted by n.
p(rk) = nk /n.
Normalized histogram provide useful image statistics.
Dr. A. NAGARAJA RAO
Image Histograms
The histogram of an image shows us the
distribution of grey levels in the image
Massively useful in image processing, especially in
segmentation
Frequencies
Grey Levels
Dr. A. NAGARAJA RAO
Histogram Examples
1 dr
ps ( s) pr (r ) pr (r )
ds ds
dr
Histogram Equalisation (cont...)
• The pdf of the output is determined by the pdf
of the input and the transformation.
• This means that we can determine the
histogram of the output image.
• A transformation of particular importance in
image processing is the cumulative distribution
function (CDF) of a random variable:
r
s T (r ) ( L 1) pr ( w) dw
0
Histogram Equalisation (cont...)
• It satisfies the first condition as the area under
the curve increases as r increases.
• It satisfies the second condition as for r=L-1 we
have s=L-1.
• To find ps(s) we have to compute
r
ds dT (r ) d
( L 1) pr ( w) dw ( L 1) pr (r )
dr dr dr 0
Histogram Equalisation (cont...)
Substituting this result:
ds
( L 1) pr (r )
dr
to
dr
ps ( s) pr (r ) Uniform pdf
ds
yields
1 1
ps ( s) pr (r ) , 0 s L 1
( L 1) pr (r ) L 1
Histogram Equalisation (cont...)
The formula for histogram equalisation in the
discrete case is given
k
( L 1) k
sk T (rk ) ( L 1) pr (rj ) nj
j 0 MN j 0
where
• rk: input intensity
• sk: processed intensity
• nj: the frequency of intensity j
• MN: the number of image pixels.
Histogram Equalisation (cont...)
Example
A 3-bit 64x64 image has the following intensities:
k
sk T (rk ) ( L 1) pr (rj )
j 0
mS xy rs,t p(rs,t )
( s ,t )S xy
S xy
2
[rs,t mS xy
]2
p ( rs ,t ).
( s ,t )S xy
The local mean and variance are the decision factors to whether apply
local enhancement or not.
(x,y) E
(x,y)
Image Mean
125 135 145 135 .. 174 164
168 175 158 149 .. 187
210 231 215 129 ..
187 192 145 200 .. Dr. A. NAGARAJA RAO
Histogram Statistics for Image Enhanc.
Arithmetic Operations
Addition, Subtraction, Multiplication, and Division
Logic Operations
AND, OR, NOT
AND
OR
Original
4
Upper-order
Bit
HE of
Error Error
Problem:
The pixel intensities in the difference image can range from -255 to 255.
Solutions:
1) Add 255 to every pixel and then divide by 2.
2) Add the minimum value of the pixel intensity in the difference image
to every pixel and then divide by 255/Max. Max is the maximum
pixel value in the modified difference image.
Dr. A. NAGARAJA RAO
Enhancement Using Arithmetic Op. Averaging
Original image Noise with zero mean
g ( x , y ) f ( x, y ) ( x, y )
1 k
g ( x , y ) g i ( x, y )
k i 1
E g ( x, y ) f ( x, y )
1 2
g ( x, y ) ( x, y )
2
k
Dr. A. NAGARAJA RAO
Enhancement Using Arithmetic Op. Averaging
Gaussian Noise
f(x,y) g(x,y) mean = 0
variance = 64
K=8 K = 16
x
- +
K = 128
K = 32
Dr. A. NAGARAJA RAO
Enhancement Using Arithmetic Op. Averaging
K=8
Difference images
between original K = 16
image and images
obtained from Notice the
averaging. mean and
K = 32 variance
of the
difference
images
K = 128 decrease as K
Dr. A. NAGARAJA RAO increases.
Basics of Spatial Filtering - Linear
a b
g ( x, y) w(s, t ) f ( x s, y t )
s a t b
mn
R wi zi
i 1
Example
Computation for the median is a nonlinear operation.
Box Weighted
filter average
Dr. A. NAGARAJA RAO
Smoothing Spatial Filtering _ Linear
Averaging (low-pass) Filters
n = filter size
n=3
n=5 n=9
n = 35
n = 15
Dr. A. NAGARAJA RAO
Smoothing Spatial Filtering
Averaging & Threshold
filter size Thrsh = 25% of
n = 15 highest intensity
3 3 Median filter [10 125 125 135 141 141 144 230 240] = 141
3 3 Max filter [10 125 125 135 141 141 144 230 240] = 240
3 3 Min filter [10 125 125 135 141 141 144 230 240] = 10
1 9
9 1
zi
Image Blurred Image
1 9
9 1
z
Robert operator
Sobel operators
Dr. A. NAGARAJA RAO
Use of First Derivative for Edge Extraction
Gradient
f f 2 2
f 2 2
2
x y
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
2 f [ f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )]
2
f 2
f
f 2 2
2
x y
1 1 1
1 -8 1
1 1 1
f ( x, y ) 2 f ( x, y )
g ( x, y )
f ( x , y ) 2
f ( xDr., A.yNAGARAJA
) RAO
Use of 2nd Derivative for Enhancement
Laplacian
2 f [ f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1) 4 f ( x, y)]
0 1 0
g(x,y) = f(x,y) - 1 -4 1 =
0 1 0
f ( x, y )
2
(b)