Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (1 vote)
84 views

Spatial Domain Image Processing)

This document discusses spatial domain image processing and enhancement techniques. It covers: 1. Spatial domain processing operates directly on pixel values, where the output value at each point is a function of neighboring input pixel values. 2. Basic intensity transformation functions include image negatives, log transformations, power-law (gamma) transformations, and piecewise-linear transformations like contrast stretching and intensity slicing. 3. Histogram processing techniques like histogram equalization are used to improve image contrast by transforming the image to have a nearly uniform histogram distribution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
84 views

Spatial Domain Image Processing)

This document discusses spatial domain image processing and enhancement techniques. It covers: 1. Spatial domain processing operates directly on pixel values, where the output value at each point is a function of neighboring input pixel values. 2. Basic intensity transformation functions include image negatives, log transformations, power-law (gamma) transformations, and piecewise-linear transformations like contrast stretching and intensity slicing. 3. Histogram processing techniques like histogram equalization are used to improve image contrast by transforming the image to have a nearly uniform histogram distribution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Computer Vision and Image

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.

Category of image enhancement


1. Spatial domain
2. Frequency domain

CV & IP 02 2
Spatial Processing of Digital Images

 Operate directly on the input image pixels.


 Output image value at point (x, y) is some
function of the input image pixel values at, or
in the neighborhood of, (x, y), as specified by
the operator T, i.e.,
g ( x, y)  T [ f ( x, y)]
 Operation is Spatial Filtering (Spatial filter, or
spatial mask, or kernel, or template, or
Window)

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)

Original input image Image negative


CV & IP 02 7
2. Log Transformations:
General form of intensity
transformation
s = T(r) = c log(1+ r)

where c is a constant and r > 0.


• Narrow range input low
intensity values mapped to
a wider range output
values. Opposite is true for
high intensity values

CV & IP 02 8
3. Power-Law
(Gamma)Transformation:
Transformation basic form
s = T(r) = c rγ

Many imaging and display devices respond inherently


according to a power law.

Assume a device has a power law response with γ =


2.5. device tends to produce darker images than
intended.

Perform gamma correction to the image by


performing the transformation s = r1/2.5 = r0.4 9
CV & IP 02
Power-Law
(Gamma)Transformation . . .

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.

(r1, s1) = (m, 0) (r1, s1) = (rmin, 0)


(r2, s2) = (m, L-1) (r2, s2) = (rmax, L-1)
CV & IP 02 14
Cont’d…
2. Intensity-level slicing:- highlights a specific
range of intensities

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.,

p(rk) = nk/MN, k = 0, 1, 2, . . ., L-1.

The histogram is an estimate of the probability of occurrence of intensity level rk


in the image.
CV & IP 02 17
Histograms…
Example:- Images and their
histograms
a) Dark image:- narrow
histogram biased towards
low intensity scale.
b) Light image:- Histogram
biased towards high
intensity scale.
c) low-contrast image:-
narrow and centered
histogram
d) High contrast image:- wide
intensity range; nearly
uniform.

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

Histogram matching is similar to histogram


equalization, except that instead of trying to
make the output image have a flat histogram, we
would like it to have a histogram of a specified
shape, say pz(z).

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)

where f (x, y): an original image


 ( x, y) : the addition of noise
One simple way to reduce this granular noise is to
take several identical pictures and average them, thus
smoothing out the randomness.
CV & IP 02 26
Spatial Filtering
Spatial filtering consists of
1. some neighborhood, and
2. predefined operation on image pixels encompassed
Linear filtering operation:
 mask (in general)
 filtering, at any point (x, y), gives the sum of products of filter
coefficients, w, and input image pixels, f, i.e.,

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

where f(x, y) - input image pixel intensity,


w(s, t) - filter weight, mask, impulse response
CV & IP 02 27
Neighbourhood Operations

Neighbourhood operations simply operate on a larger


neighbourhood of pixels than point operations
Origin x
 Neighbourhoods are
mostly a rectangle
around a central pixel

 Any size rectangle Neighbourhood


(x, y)

and any shape filter


are possible

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

central pixel are more


2/ 4/ 2/
16 16 16
important.

 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.

 good for removal of salt-and-pepper type of noise


isolated clusters of pixels whose intensities are
different from their neighbors.

 similarly max filter (replace pixel value by the


largest pixel value in the set) and also min filter.
CV & IP 02 35
Example
For the center colored pixels determine the value if
the following filters are applied. (Assume 3x3 filter
mask) 205 80
100
100
1. Max filter
190 200 205
A 190
2. Min filter 210
75 180
B 200
3. Average filter
80 170 180 100
4. Weighted average filter

5. Median filter
CV & IP 02 36
Averaging Filter Vs. Median Filter Example

Original Image Image After Image After


With Noise Averaging Filter Median Filter

Filtering is often used to remove noise from images.


Sometimes a median filter works better than an
averaging filter.
CV & IP 02 37
Strange Things Happen At The Edges!......
?
 At the edges of an image we are missing pixels to
form a neighbourhood
rigin x
e

CV & IP 02 38
e
y
Strange Things Happen At The Edges! (cont…)

There are a few approaches to dealing with


missing edge pixels:
 Omit missing pixels
Can add extra code and slow down processing
 Pad the image
Typically with either all white or all black pixels
 Replicate border pixels
 Truncate the image

CV & IP 02 39
Sharpening Spatial Filters
 Previously we have looked at smoothing filters which
remove fine detail

 Sharpening spatial filters seek to highlight fine detail


1. Remove blurring from images
2. Highlight edges

 Sharpening filters are based on spatial differentiation

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

 Simply takes into account the values both before


and after the current value

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

80 170 180 100

CV & IP 02 46
Using Second Derivatives For
Image Enhancement
The 2nd derivative is more useful for image
enhancement.

 Stronger response to fine detail


 Simpler implementation

CV & IP 02 47
What are edges in an image?

 Edges are those


places in an image
that correspond to
object boundaries.
 Edges are pixels
where image
brightness changes
abruptly.
CV & IP 02 Brightness vs. Spatial Coordinates
48
The Laplacian
The Laplacian is defined as follows:
2 f 2 f
 f  2  2
2

 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

and in the y direction as follows:


2 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
 y
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 Laplacian


Image Filtered Image Filtered Image
CV & IP 02 Scaled for Display 52
But That Is Not Very Enhanced!
 The result of a Laplacian filtering is not
an enhanced image

 We have to do more work in order to get


our final image

 Subtract the Laplacian result from the


original image to generate our final
sharpened enhanced image
Laplacian
g ( x, y)  f ( x, y)   f
CV & IP 02
2 Filtered Image
Scaled for Display
53
Laplacian Image Enhancement

- =
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

LAPLACIAN Original Image Sharpened Image

CV & IP 02 56
Unsharp masking:

Subtract a BLURRED version of an image


from the image itself !

Fsharp =F–F
blurred

CV & IP 02 57
Unsharp masking):

Variation: emphasize original image


(high-boost filtering):

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.

1. Laplacian 100 205 80


100
2. Unsharp masking (Consider 3x3 mask) 190 200 205
190
75 180 210
200

80 170 180 100

CV & IP 02 59
Combining Spatial Enhancement
Methods
 Successful image enhancement is
typically not achieved using a single
operation

 Rather we combine a range of


techniques in order to achieve a final
result

 This example will focus on


enhancing the bone scan to the right
CV & IP 02 60
Combining Spatial Enhancement
Methods (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

(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

Image (d) smoothed with a 5*5


averaging filter
Combining Spatial Enhancement
Methods (cont.…)
Compare the original and final images

CV & IP 02 63
Thank you!!!
Any ???

CV & IP 02 64

You might also like