Spatial Domain Image Processing)
Spatial Domain Image Processing)
processing (CoSc4151)
Chapter Three
Spatial domain image processing
Jimma University
Jimma Institute of Technology
For Computer Science students
Abel W.
Objective of image processing
The principal objective of enhancement is to process an
images so that the result is more suitable than the original
image for a SPECIFIC application.
CV & IP 02 2
Spatial Processing of Digital Images
CV & IP 02 3
Cont’d…
CV & IP 02 4
Cont’d…
1 x 1 neighborhood, get a pixel-to-pixel mapping
and T becomes an intensity transformation
Examples s T (r ), s output pixel intensity at (x, y),
r input pixel intensity at (x, y)
CV & IP 02 5
Contrast stretching Thresholding (binary output)
Basic Intensity Transformation
Functions
1. Image negatives:- image intensity range [0, L-1]
Negative transformation
s = T(r) = L – 1 – r
•
CV & IP 02 6
Image negative cont’d…
Example:- Digital mammogram (breast X-ray showing some
lesion)
CV & IP 02 8
3. Power-Law
(Gamma)Transformation:
Transformation basic form
s = T(r) = c rγ
CV & IP 02 10
Example:- Gamma correction of a
ramp image
CV & IP 02 11
Example:- General-purpose
Contrast manipulation
CV & IP 02 12
Example:- Contrast manipulation
CV & IP 02 13
4. Piecewise-Linear
Transformation:
1.Contrast stretching:
expands the range of
intensity levels so
that it spans the full
intensity range.
CV & IP 02 15
Image histograms
In Statistics, Histogram is a graphical representation
showing a visual impression of the distribution of
data.
CV & IP 02 16
Histogram
Assume a digital M x N image with intensity level in [0, L-1]
The histogram is a discrete function
h(rk) = nk
where
rk - kth intensity value of input image
nk - number of pixels in the image with intensity rk
Normalize the histogram by dividing it by the total number of pixels in the image,
i.e.,
CV & IP 02 18
Histogram Processing
CV & IP 02 19
Histogram Processing
CV & IP 02 20
Histogram Equalization
In discrete version:
The probability of occurrence of gray level rk in an image is
nk
pr ( r ) k 0,1,2,..., L 1
n
n : the total number of pixels in the image
nk : the number of pixels that have gray level rk
L : the total number of possible gray levels in the image
The transformation function is
k k nj
sk T (rk ) pr (rj ) k 0,1,2,..., L 1
j 0 j 0 n
Thus, an output image is obtained by mapping each pixel with level rk in the
input image into a corresponding pixel with level sk.
CV & IP 02 21
Histogram Equalization
Histogram equalization:
1. To improve the contrast of an image
2. To transform an image in such a way that the transformed image
has a nearly uniform distribution of pixel values
Transformation:
Assume r has been normalized to the interval [0,1], with r = 0
representing black and r = 1 representing white
s T (r ) 0 r 1
The transformation function satisfies the following conditions:
T(r) is single-valued and monotonically increasing in the interval
0 T (r ) 1 for 0 r 1
CV & IP 02 22
Histogram Equalization
For example:
CV & IP 02 23
Histogram equalized image and its histogram
CV & IP 02 24
Histogram Matching/specification
CV & IP 02 25
Image Averaging
When taking pictures in reduced lighting (i.e., low
illumination), image noise becomes apparent.
A noisy image g(x, y) can be defined by
g ( x, y) f ( x, y) ( x, y)
g ( x, y ) w(1,1) f ( x 1, y 1) w(1,0) f ( x 1, y )
w(0,0) f ( x, y ) w(1,1) f ( x 1, y 1)
a b
w(s, t ) f ( x s, y t )
s a t b
CV & IP 02 y 28
Image f (x, y)
Neighbourhood Operations
For each pixel in the origin image, the outcome is written on
the same location at the target image.
Origin x
Target
(x, y)
Neighbourhood
y Image f (x, y)
CV & IP 02 29
The Spatial Filtering Process
Origin x
a b c j k l
d e f * m
p
n
q
o
r
g h i
Filter (w)
Simple 3*3 Original Image
e 3*3 Filter Pixels
Neighbourhood
eprocessed = n*e +
j*a + k*b + l*c +
m*d + o*f +
y Image f (x, y) p*g + q*h + r*i
The above is repeated for every pixel in the original image to
generate
CV & IP 02the filtered image 30
Smoothing Spatial Filters
One of the simplest spatial filtering operations we can
perform is a smoothing operation
Simply average all of the pixels in a neighbourhood
around a central value
1/ 1/ 1/
Especially useful 9 9 9
in removing noise
1/ 1/ 1/
from images 9 9 9
Simple
Also useful for 1/ 1/ 1/ averaging
highlighting gross 9 9 9
filter
CV & IP 02
detail 31
Smoothing Spatial Filtering
Origin x
104 100 108 1/ 1/ 1/
9 9 9
99 106 98
95 90 85
* 1/ 1/ 1/
1/
9 9 9
1/ 1/
9 9 9
1104
/9 1100
/9 1108
/9
Original Image Filter
Simple 3*3 1/
999 1106
/9 198
/9
3*3 Smoothing Pixels
Neighbourhood 195
/9 190
/9 185
/9 Filter
e = 1/9*106 +
1/ *104 + 1/ *100 + 1/ *108 +
9 9 9
1/ *99 + 1/ *98 +
9 9
y Image f (x, y) 1/ *95 + 1/ *90 + 1/ *85
9 9 9
= 98.3333
The above is repeated for every pixel in the original image to
CV & IP 02 32
generate the smoothed image.
Image Smoothing Example
The image at the top left is an
original image of size 500*500
pixels
The subsequent images show the
image after filtering with an
averaging filter of increasing
sizes 3, 5, 9, 15 and 35
Notice how detail begins to
disappear
CV & IP 02 33
Weighted Smoothing Filters
More effective smoothing filters can be generated
by allowing different pixels in the neighbourhood
different weights in the averaging function
1/ 2/ 1/
Pixels closer to the 16 16 16
Often referred to as a 1/
16
2/
16
1/
16
weighted averaging
CV & IP 02
Weighted averaging filter 34
Order-Statistic (nonlinear)
Filters:
median filter forces pixels with distinct intensity
levels to be more like their neighbors.
5. Median filter
CV & IP 02 36
Averaging Filter Vs. Median Filter Example
CV & IP 02 38
e
y
Strange Things Happen At The Edges! (cont…)
CV & IP 02 39
Sharpening Spatial Filters
Previously we have looked at smoothing filters which
remove fine detail
CV & IP 02 40
1st Derivative
The formula for the 1st derivative of a function
is as follows:
f
f ( x 1) f ( x)
x
It’s just the difference between subsequent
values and measures the rate of change of the
function
CV & IP 02 41
1st Derivative (cont…)
Image Strip
8
7
6
5
f(x) 4
3
2
1
0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
0 -1 -1 -1 -1 0 0 6 -6 01st0Derivative
0 1 2 -2 -1 0 0 0 7 0 0 0
8
6
4
2
f’(x) 0
-2
-4
-6
CV
-8
& IP 02 42
2nd Derivative
the formula for the 2nd derivative of a function is as
follows:
f 2
f ( x 1) f ( x 1) 2 f ( x)
x
2
CV & IP 02 43
2nd Derivative (con’t…)
CV & IP 02 44
1st and 2nd Derivative
Image Strip
8
7
6
5
4
3
f(x) 2
1
0
1st Derivative
8
6
4
2
0
f’(x) -2
-4
-6
-8
2nd Derivative
10
-5
f’’(x) -10
CV & IP 02 45
-15
Example
For the center colored pixels determine the value if
the following filters are applied in horizontal
direction only. 205 80
100
100
i. First derivative
190 200 205
190
ii. Second derivative
75 180 210
200
CV & IP 02 46
Using Second Derivatives For
Image Enhancement
The 2nd derivative is more useful for image
enhancement.
CV & IP 02 47
What are edges in an image?
x y
where the partial 1st order derivative in the x
direction is defined as follows:
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2
CV & IP 02 49
The Laplacian
2 f
f(x-1,y) f(x,y) f(x+1,y) f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
f(x,y-1)
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
f(x,y)
f(x,y+1)
CV & IP 02 50
2-Dimentional Laplacian
• The digital implementation of the 2-Dimensional
Laplacian is obtained by summing 2 components
2
f 2
f
2 f 2 2
x x
2 f f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1) 4 f ( x, y)
1 0 1 0
1 -4 1 1 -4 1
1 0 1 0
CV & IP 02 51
The Laplacian (con’t…)
Applying the Laplacian to an image we get a new
image that highlights edges and other discontinuities
- =
Original Laplacian Sharpened
Image Filtered Image Image
In the final sharpened image edges and fine detail are
much more obvious
CV & IP 02 54
Simplified Image Enhancement
The entire enhancement can be combined into a
single filtering operation
g ( x, y) f ( x, y) 2 f
f ( x, y) [ f ( x 1, y) f ( x 1, y)
f ( x, y 1) f ( x, y 1)
4 f ( x, y)]
5 f ( x, y) f ( x 1, y) f ( x 1, y)
CV & IP 02 f ( x, y 1) f ( x, y 1)
55
Simplified Image Enhancement
Sharpening can be done in 1 pass:
0 -1 0 0 0 0 0 -1 0
-1 4 -1 + 0 1 0 = -1 5 -1
0 -1 0 0 0 0 0 -1 0
CV & IP 02 56
Unsharp masking:
Fsharp =F–F
blurred
CV & IP 02 57
Unsharp masking):
F = a*F – F
sharp blurred , a>=1
0 -1 0 0 0 0 0 1 0
-1 a-1 -1 = 0 a 0 - 1 1 1
0
CV & IP 02
-1 0 0 0 0 0 1 0 58
Example
For the center colored pixel determine the value if the
following filters are applied.
CV & IP 02 59
Combining Spatial Enhancement
Methods
Successful image enhancement is
typically not achieved using a single
operation
(a)
Laplacian filter of
bone scan (a) (b)
Sharpened version of
bone scan achieved by
subtracting (a) and (b) (c)
CV & IP 02 Sobel filter of bone 61
scan (a)
(d)
Combining Spatial Enhancement
Methods (con’t…)
Result of applying a
power-law trans. to
Sharpened image (h)
The product of (g)
which is sum of (a) (g)
(c) and (e)
which will be and (f) (f)
used as a mask
(e)
CV & IP 02 62
CV & IP 02 63
Thank you!!!
Any ???
CV & IP 02 64