Image Processing
Image Processing
Recognition (IPPR):
Introduction (Lecture 1)
1 pixel
7
of
92
What is a Digital Image? (cont…)
Common image formats include:
– 1 sample per point (B&W or Grayscale)
– 3 samples per point (Red, Green, and Blue)
– 4 samples per point (Red, Green, Blue, and “Alpha”,
a.k.a. Opacity)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
26
of
Key Stages in Digital Image Processing:
92 Image Aquisition
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
27
of
Key Stages in Digital Image Processing:
92 Image Enhancement
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
28
of
Key Stages in Digital Image Processing:
92 Image Restoration
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
29
of
Key Stages in Digital Image Processing:
92 Morphological Processing
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
30
of
Key Stages in Digital Image Processing:
92 Segmentation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
31
of
Key Stages in Digital Image Processing:
92 Object Recognition
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
32
of
Key Stages in Digital Image Processing:
92 Representation & Description
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
33
of
Key Stages in Digital Image Processing:
92 Image Compression
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
34
of
Key Stages in Digital Image Processing:
92 Colour Image Processing
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
35
of
92
Summary
We have looked at:
– What is a digital image?
– What is digital image processing?
– History of digital image processing
– State of the art examples of digital image
processing
– Key stages in digital image processing
36
of
92
Contents
This lecture will cover:
The human visual system
Light and the electromagnetic spectrum
Image representation
Image sensing and acquisition
Sampling, quantisation and resolution
37
of
92
Human Visual System
The best vision model we have!
Knowledge of how images form in the eye
can help us with processing digital images
We will take just a whirlwind tour of the
human visual system
38
of
92
Structure Of The Human Eye
The lens focuses light from objects onto the
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
retina
The retina is covered with
light receptors called
cones (6-7 million) and
rods (75-150 million)
Cones are concentrated
around the fovea and are
very sensitive to colour
Rods are more spread out
and are sensitive to low levels of illumination
39
of
92
Blind-Spot Experiment
Draw an image similar to that below on a
piece of paper (the dot and cross are about
6 inches apart)
of
92
43
Brightness Adaptation & Discrimination
(cont…)
44
of
Brightness Adaptation & Discrimination
92 (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Our visual
systems play lots
of interesting
tricks on us
48
of
92
Light And The Electromagnetic Spectrum
Light
absorbed, while green
n
Gree
matrices row
52
of
92
Image Acquisition
Images are typically generated by
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Imaging Sensor
of
92
54
of
92
56
Image Sampling And Quantisation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
57
Image Sampling And Quantisation
58
of
Image Sampling And Quantisation
92 (cont…)
Remember that a digital image is always
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
59
Image Representation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
60
Image Representation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
61
Image Representation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
62
Image Representation
63
of
92
Spatial Resolution
The spatial resolution of an image is
determined by how sampling was carried out
Spatial resolution simply refers to the
smallest discernable detail in an image
Vision specialists will
often talk about pixel
size
Graphic designers will
talk about dots per 5.1
g a pixel
Me
inch (DPI) s
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
64
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
65
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
66
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
67
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
68
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
69
Spatial Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
70
Spatial Resolution (cont…)
71
of
92
Intensity Level Resolution
Intensity level resolution refers to the
number of intensity levels used to represent
the image
The more intensity levels used, the finer the level of detail
discernable in an image
Intensity level resolution is usually given in terms of the
number of bits used to store each intensity level
Number of Intensity
Number of Bits Examples
Levels
1 2 0, 1
2 4 00, 01, 10, 11
4 16 0000, 0101, 1111
8 256 00110011, 01010101
16 65,536 1010101010101010
72
of
92
Intensity Level Resolution (cont…)
256 grey levels (8 bits per pixel) 128 grey levels (7 bpp) 64 grey levels (6 bpp) 32 grey levels (5 bpp)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
16 grey levels (4 bpp) 8 grey levels (3 bpp) 4 grey levels (2 bpp) 2 grey levels (1 bpp)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
73
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
74
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
75
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
76
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
77
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
78
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
79
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
80
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
81
Saturation & Noise
82
of
92
Resolution: How Much Is Enough?
The big question with resolution is always
how much is enough?
This all depends on what is in the image and what
you would like to do with it
Key questions include
• Does the image look aesthetically pleasing?
• Can you see what you need to see within the
image?
83
of
Resolution: How Much Is Enough?
92 (cont…)
of
92
85
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
86
Intensity Level Resolution (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
92
87
Intensity Level Resolution (cont…)
88
of
92
Summary
We have looked at:
Human visual system
Light and the electromagnetic spectrum
Image representation
Image sensing and acquisition
Sampling, quantisation and resolution
Next time we start to look at techniques for
image enhancement
Image Processing and Pattern
Recognition (IPPR):
(Lecture 2)
• How many samples and gray levels are required for a “good”
approximation?
• The resolution (the degree of discernible detail) depends strongly on
these two parameters
18
of
Effects of reducing spatial
90
resolution
19
of
90
Effects of reducing gray levels
20
of
Basic relationships between
90
pixels
An image is denoted by: f(x,y)
Lowercase letters (e.g. p, q) will denote individual pixels
A subset of f(x,y) is denoted by S
Neighbors of a pixel:
– A pixel p at (x,y) has 4 horizontal/vertical neighbors at
• (x+1,y),(x-1,y),(x,y+1)and(x,y-1)
• called the 4-neighbors of p: N4(p)
– A pixel p at (x,y) has 4 diagonal neighbors at
• (x+1,y+1),(x+1,y-1),(x-1,y+1)and(x-1,y-1)
• called the diagonal–neighbors of p:ND(p)
– The 4-neighbors and the diagonal-neighbors of p are called
the 8-neighbors of p: N8(p)
21
of
90
Connectivity between pixels
• Connectivity is an important concept in establishing boundaries of
object and components of regions in an image
• When are two pixels connected?
– If they are adjacent in some sense (say they are 4-neighbors)
– and, if their gray levels satisfy a specified criterion of similarity (say
they are equal)
• Example: given a binary image (e.g. gray scale = [0,1]), two pixels
may be 4-neighbors but are not considered connected unless they
have the same value
22
of
90
Connectivity between pixels
• Let V be the set of values used to determine connectivity
– For example, in a binary image, V={1} for the connectivity of pixels
with a value of 1
– In a gray scale image, for the connectivity of pixels with a range of
intensity values of, say, 32 to 64, it follows that V={32,33,...,63,64}
– Consider three types of connectivity
• 4-connectivity: Pixels p and q with values from V are 4-connected if q is
in the set N4(p)
• 8-connectivity: Pixels p and q with values from V are 8-connected if q is
in the set N8(p)
• m-connectivity (mixed): Pixels p and q with values from V are
m-connected if
– q is in the set N4(p),or
– q is in the set ND(p) and the set N4(p) ∩ N4(q) is empty (This is the set of
pixels that are 4-neighbors of p and q and whose values are from V)
23
of
90
Connectivity between pixels
24
of
90
Pixel adjacencies and paths
• Pixel p is adjacent to q if they are connected
– We can define 4-, 8-, or m-adjacency depending on the
specified type of connectivity
• Two image subsets S1 and S2 are adjacent if some pixel in S1
is adjacent to S2
• A path from p at (x,y) to q at (s,t) is a sequence of distinct
pixels with coordinates (x0,y0), (x1,y1),....., (xn,yn)
– Where (x0,y0)=(x,y) and (xn,yn)=(s,t) and
– (xi,yi) is adjacent to (xi-1,yi-1) for 1<= i <= n
– n is the length of the path
• If p and q are in S, then p is connected to q in S if there is a
path from p to q consisting entirely of pixels in S
25
of
90
Example paths
26
of
90
Connected components
• For any pixel p in S, the set of pixels connected to p form a
connected component of S
• Distinct connected components in S are said to be disjoint
27
of
Labeling 4-connected
90
components
• Consider scanning an image pixel by pixel from left to right and
top to bottom
of
90
46
Image Enhancement Examples
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
47
Image Enhancement Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
48
Image Enhancement Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
49
Image Enhancement Examples (cont…)
50
of
90
Spatial & Frequency Domains
There are two broad categories of image
enhancement techniques
– Spatial domain techniques
• Direct manipulation of image pixels
– Frequency domain techniques
• Manipulation of Fourier transform or wavelet
transform of an image
For the moment we will concentrate on
techniques that operate in the spatial
domain
51
of
Basic Spatial Domain Image
90 Enhancement
Most spatial domain enhancement operations
can be reduced to the form
Origin x
g (x, y) = T[ f (x, y)]
where f (x, y) is the
input image, g (x, y) is
the processed image (x, y)
and T is some
operator defined over
some neighbourhood
of (x, y) y Image f (x, y)
52
of
90
Point Processing
The simplest spatial domain operations
occur when the neighbourhood is simply the
pixel itself
In this case T is referred to as a grey level
transformation function or a point processing
operation
Point processing operations take the form
s=T(r)
where s refers to the processed image pixel
value and r refers to the original image pixel
value
53
of
Point Processing Example:
90 Negative Images
Negative images are useful for enhancing
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Original Negative
s = 1.0 - r
Image Image
54
of
Point Processing Example:
90 Negative Images (cont…)
Original Image Enhanced Image x
x
s = intensitymax - r
55
of
Point Processing Example:
90 Thresholding
Thresholding transformations are particularly
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
57
Intensity Transformations
58
of
90
Basic Grey Level Transformations
There are many different kinds of grey level
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
transformations
Three of the most
common are shown
here
– Linear
• Negative/Identity
– Logarithmic
• Log/Inverse log
– Power law
• nth power/nth root
59
of
90
Logarithmic Transformations
The general form of the log transformation is
s = c * log(1 + r)
The log transformation maps a narrow range
of low input grey level values into a wider
range of output values
The inverse log transformation performs the
opposite transformation
Compresses the dynamic range of images
with large variations in pixel values
60
of
90
Logarithmic Transformations (cont…)
s = log(1 + r)
61
of
90
Logarithmic Transformations (cont…)
s = log(1 + r)
We usually set c to 1
Grey levels must be in the range [0.0, 1.0]
62
of
90
Power Law Transformations
Power law transformations have the following
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
form
s=c*rγ
Map a narrow range
of dark input values
into a wider range of
output values or vice
versa
Varying gives a whole
family of curves
63
of
90
Power Law Transformations (cont…)
Original Image Enhanced Image x
x
s=rγ
We usually set c to 1
Grey levels must be in the range [0.0, 1.0]
64
of
90
Power Law Example
65
of
90
Power Law Example (cont…)
γ = 0.6
1
0.9
T ran sfo rm ed In ten sities
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Old Intensities
66
of
90
Power Law Example (cont…)
γ = 0.4
1
0.9
Transformed Intensities
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities
67
of
90
Power Law Example (cont…)
γ = 0.3
1
0.9
Transformed Intensities
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities
68
of
90
Power Law Example (cont…)
The images to the
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
right show a
s = r 0.6
magnetic resonance
(MR) image of a
fractured human
s = r 0.4
spine
Different curves
highlight different
detail
69
of
90
Power Law Example
70
of
90
Power Law Example (cont…)
γ = 5.0
1
0.9
Transformed Intensities
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities
71
of
90
Power Law Transformations (cont…)
An aerial photo
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of a runway is
shown s = r 3.0
This time
power law
transforms are
s = r 4.0
used to darken
the image
Different curves
highlight
different detail
72
of
90
Gamma Correction
Many devices used for image capture, display and printing
respond according to a power law
• The exponent in the power-law equation is referred to as
gamma
• The process of correcting for the power-law response is
referred to as gamma correction
• Example: – CRT devices have an intensity-to-voltage
response that is
a power function (exponents typically range from 1.8-2.5)
– Gamma correction in this case could be achieved by
applying the transformation s=r1/2.5=r^0.4
73
of
90
Gamma Correction
Many of you might be familiar with gamma
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
74
More Contrast Issues
75
of
Piecewise Linear Transformation
90 Functions
Rather than using a well defined mathematical
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
– Similar to thresholding
– Other levels can be
suppressed or maintained
– Useful for highlighting features
in an image
79
of
90
Bit Plane Slicing
Often by isolating particular bits of the pixel
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
[10000000] [01000000]
[00100000] [00001000]
[00000100] [00000001]
81
of
90
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
[10000000] [01000000]
[00100000] [00001000]
[00000100] [00000001]
82
of
90
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
83
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
84
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
85
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
86
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
87
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
88
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
89
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
90
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
91
Bit Plane Slicing (cont…)
92
of
90
Bit Plane Slicing (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Reconstructed image
using only bit planes 8 and
7
Reconstructed image
using only bit planes 8, 7
and 6
Reconstructed image
using only bit planes 7, 6
and 5
Image Processing and Pattern
Recognition (IPPR):
(Lecture 3)
Grey Levels
3
of
30
Image Histograms
• The histogram of a digital image, f, (with intensities [0,L-1])
is a discrete function
h(rk) = nk
• Where rk is the kth intensity value and nk is the number of
pixels in f with intensity rk
• Normalizing the histogram is common practice – Divide the
components by the total number of pixels in the image –
Assuming an MxN image, this yields
p(rk) = nk/MN for k=0,1,2,....,L-1 – p(rk) is, basically, an estimate
of the probability of occurrence of intensity level rk in an image
Σ p(rk) = 1
4
of
30
Uses for Histogram Processing
• Image enhancements
• Image statistics
• Image compression
• Image segmentation
• Simple to calculate in software
• Economic hardware implementations
– Popular tool in real-time image processing
• A plot of this function for all values of k provides a global
description of the appearance of the image (gives useful information
for contrast enhancement)
• Histograms commonly viewed in plots as
h(rk) = nk versus rk
p(rk) = nk /MN versus rk
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
5
of
30
Histogram Examples
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
6
of
30
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
7
of
30
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
8
of
30
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
9
of
30
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
10
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
11
30
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
12
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
13
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
14
Histogram Examples (cont…)
15
of
30
Histogram Examples (cont…)
A selection of images and
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
their histograms
Notice the relationships
between the images and
their histograms
Note that the high contrast
image has the most
evenly spaced histogram
16
of
30
Contrast Stretching
We can fix images that have poor contrast
by applying a pretty simple contrast
specification
The interesting part is how do we decide on
this transformation function?
17
of
30
Histogram Equalisation
• Histogram equalization is a process for increasing the
contrast in an image by spreading the histogram out to be
approximately uniformly distributed
• The gray levels of an image that has been subjected to
histogram equalization are spread out and always reach
white
– The increase of dynamic range produces an increase in
contrast
• For images with low contrast, histogram equalization has
the adverse effect of increasing visual graininess
18
of
30
Histogram Equalisation
• The intensity transformation function we are constructing
is of the form
s=T(r) 0 ≤ r ≤ L−1
of
30
23
Equalisation Transformation Function
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
24
1
Equalisation Examples
25
of
30
Equalisation Transformation Functions
of
30
26
2
Equalisation Examples
27
of
30
Equalisation Transformation Functions
of
30
28
4
3
Equalisation Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
30
29
4
3
Equalisation Examples (cont…)
30
of
30
Equalisation Transformation Functions
Neighbourhoods are
mostly a rectangle
around a central pixel
(x, y)
Any size rectangle Neighbourhood
y y
8
of
43
The Spatial Filtering Process
Origin x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3
e 3*3 Filter Pixels
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
w(s, t ) f ( x s, y t )
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
g ( x, y )
s at b
95 90 85
* 1/
9
1/
9
1/
9
9 9 9
1/ 100
104
9
1/ 108
9
1/
9
Original Image Filter
Simple 3*3 1/
99 1/ 1/
9 98
9 106 9
3*3 Smoothing Pixels
Neighbourhood /9 190
195 /9 /9
185 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 generate the smoothed image
13
of
43
Image Smoothing Example
The image at the top left
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
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
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
14
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
15
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
16
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
17
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
18
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
19
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
20
Image Smoothing Example
21
of
43
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/
important 16 16 16
Often referred to as a
1/ 2/ 1/
weighted averaging 16 16 16
Weighted
averaging filter
22
of
43
Another Smoothing Example
By smoothing the original image we get rid
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
23
Another Smoothing Example
24
of
43
Smoothing Filters
• One problem with the lowpass filter is it blurs edges and other sharp
details
• If the intent is to achieve noise reduction, one approach can be to use
median filtering
– The value of each pixel is replaced by the median pixel value in
the neighborhood (as opposed to the average)
– Particularly effective when the noise consists of strong, spike like
components and edge sharpness is to be preserved
• The median m of a set of values is such that half of the values are
greater than m and half are less than m
• To implement, sort the pixel values in the neighborhood, choose the
median and assign this value to the pixel of interest
• Forces pixels with distinct intensities to be more like their neighbors
25
of
Averaging Filter Vs. Median Filter
43 Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
26
Example
Averaging Filter Vs. Median Filter
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
27
Example
Averaging Filter Vs. Median Filter
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
28
Example
Averaging Filter Vs. Median Filter
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
29
Example
Averaging Filter Vs. Median Filter
30
of
43
Sharpening Filters (High Pass)
• The shape of the impulse response needed to implement a
high-pass (sharpening) filter indicates the filter should have
positive coefficients near its center and negative coefficients in
the outer periphery
• For a 3x3 mask, the simplest arrangement is to have the
center coefficient positive and all others negative
31
of
43
Sharpening Filters (High Pass)
• Note the sum of the coefficients is zero
– When the mask is over a constant or slowly varying region the
output is zero or very small
• This filter eliminates the zero-frequency term
• Eliminating this term reduces the average gray-level value in
the image to zero (will reduce the global contrast of the image)
• Result will be a some what edge-enhanced image over a dark
background
• Reducing the average gray-level value to zero implies some negative
gray levels
– The output should be scaled back into an appropriate range
[0, L-1]
32
of
43
Sharpening Filters (High Pass)
33
of
43
Sharpening Filters (High-boost)
• A high-pass filter may be computed as:
High-pass = Original - Lowpass
• Multiplying the original by an amplification factor yields a high-boost or
high-frequency-emphasis filter
High-boost = A(Original) − Lowpass
= ( A − 1)(Original ) + Original − Lowpass
= ( A − 1)(Original ) + High-pass
– If A>1, part of the original image is added to the high-pass result
(partially restoring low frequency components)
– Result looks more like the original image with a relative degree of
edge enhancement that depends on the value of A
– May be implemented with the center coefficient value w=9A-1
(A≥1)
34
of
43
Sharpening Filters (High-boost)
35
of
Simple Neighbourhood Operations
43 Example
x
123 127 128 119 115 130
y
36
of
43
Strange Things Happen At The Edges!
e e e
y Image f (x, y)
37
of
Strange Things Happen At The Edges!
43 (cont…)
There are a few approaches to dealing with
missing edge pixels:
Omit missing pixels
• Only works with some filters
• 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
Allow pixels wrap around the image
• Can cause some strange image artefacts
38
of
Simple Neighbourhood Operations
43 Example
x
123 127 128 119 115 130
y
39
of
Strange Things Happen At The Edges!
43 (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Filtered Image:
Zero Padding
Filtered Image:
Wrap Around Edge Pixels
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
40
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
41
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
42
Strange Things Happen At The Edges!
(cont…)
43
of
43
Correlation & Convolution
The filtering we have been talking about so
far is referred to as correlation with the filter
itself referred to as the correlation kernel
Convolution is a similar operation, with just
one subtle difference
a b c r s t eprocessed = v*e +
z*a + y*b + x*c +
d
f
e
g h
e
* u
x
v
y
w
z
w*d + u*e +
t*f + s*g + r*h
Original Image Filter
Pixels
a function
Let’s consider a simple 1 dimensional
example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
6
of
32
A
B
Spatial Differentiation
7
of
32
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
8
of
32
1st Derivative (cont…)
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 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
9
of
32
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
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
-1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0
11
of
Using Second Derivatives For Image
32 Enhancement
The 2nd derivative is more useful for image
enhancement than the 1st derivative
– Stronger response to fine detail
– Simpler implementation
– We will come back to the 1st order derivative
later on
The first sharpening filter we will look at is
the Laplacian
– Isotropic
– One of the simplest sharpening filters
– We will look at a digital implementation
12
of
32
The Laplacian
The Laplacian is defined as follows:
f f2 2
f 2 2
2
x y
where the partial 1st order derivative in the x
direction is defined as follows:
f2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2
f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
We can easily build a filter based on this
0 1 0
1 -4 1
0 1 0
14
of
32
The Laplacian (cont…)
Applying the Laplacian to an image we get a
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
enhanced image
g ( x, y ) f ( x, y ) f
2
16
of
32
Laplacian Image Enhancement
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
- =
Original Laplacian Sharpened
Image Filtered Image Image
of
32
17
Laplacian Image Enhancement
18
of
32
Simplified Image Enhancement
The entire enhancement can be combined
into a single filtering operation
g ( x, y ) f ( x, y ) f
2
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 )
f ( x, y 1) f ( x, y 1)
19
of
32
Simplified Image Enhancement (cont…)
0 -1 0
-1 5 -1
0 -1 0
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
20
Simplified Image Enhancement (cont…)
21
of
32
Variants On The Simple Laplacian
There are lots of slightly different versions of
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
-1 -1 -1
-1 9 -1
-1 -1 -1
22
of
32
1st Derivative Filtering
Implementing 1st derivative filters is difficult in
practice
For a function f(x, y) the gradient of f at
coordinates (x, y) is given as the column
vector:
f
Gx x
f f
G y
y
23
of
32
1st Derivative Filtering (cont…)
The magnitude of this vector is given by:
f mag (f )
G G2
x
2
y
1
2
1
f f
2 2 2
x y
z1 z2 z3
z4 z5 z6
z7 z8 z9
25
of
32
Sobel Operators
Based on the previous equations we can
derive the Sobel Operators
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
An image of a
contact lens which
is enhanced in
order to make
defects (at four
and five o’clock in
the image) more
obvious
(a)
Laplacian filter of
bone scan (a)
(b)
Sharpened version of
bone scan achieved (c)
by subtracting (a)
and (b) Sobel filter of bone
scan (a) (d)
31
of
Combining Spatial Enhancement
32 Methods (cont…)
Result of applying a (h)
power-law trans. to
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
DFT
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
61
118
DFT & Images
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
62
118
DFT & Images
63
of
118
DFT & Images (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
DFT
of
64
118
DFT & Images (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
65
118
DFT & Images (cont…)
66
of
118
The Inverse DFT
It is really important to note that the Fourier
transform is completely reversible
The inverse DFT is given by:
M 1 N 1
1
f ( x, y )
MN
F (u , v ) e
u 0 v0
j 2 ( ux / M vy / N )
of
69
118
Some Basic Frequency Domain Filters
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
70
118
Some Basic Frequency Domain Filters
71
of
118
Smoothing Frequency Domain Filters
1 if D (u , v ) D0
H (u , v )
0 if D (u , v ) D0
where D(u,v) is given as:
D (u , v ) [( u M / 2 ) ( v N / 2 ) ]
2 2 1/ 2
74
of
118
Ideal Low Pass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
75
118
Ideal Low Pass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
76
118
Ideal Low Pass Filter (cont…)
77
of
118
Ideal Low Pass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Result of filtering
Original with ideal low pass
image filter of radius 5
Result of filtering
Result of filtering
with ideal low pass
with ideal low pass
filter of radius 230
filter of radius 80
78
of
118
Ideal Low Pass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Result of filtering
with ideal low pass
filter of radius 5
79
of
118
Ideal Low Pass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Result of filtering
with ideal low pass
filter of radius 15
80
of
118
Butterworth Lowpass Filters
The transfer function of a Butterworth lowpass
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Result of filtering
Original with Butterworth filter
image of order 2 and cutoff
radius 5
Result of filtering
Result of filtering with
with Butterworth filter
Butterworth filter of
of order 2 and cutoff
order 2 and cutoff
radius 230
radius 80
82
of
118
Butterworth Lowpass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Original
image
Result of filtering
with Butterworth filter
of order 2 and cutoff
radius 5
83
of
118
Butterworth Lowpass Filter (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Result of filtering
Original with Gaussian filter
image with cutoff radius 5
Result of filtering
Result of filtering
with Butterworth
with ideal low pass
filter of order 2
filter of radius 15
and cutoff radius
15
Result of filtering
with Gaussian
filter with cutoff
radius 15
87
of
118
Lowpass Filtering Examples
A low pass Gaussian filter is used to connect
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
broken text
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
88
118
Lowpass Filtering Examples
89
of
118
Lowpass Filtering Examples (cont…)
Different lowpass Gaussian filters used to
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
90
118
Lowpass Filtering Examples (cont…)
91
of
118
Lowpass Filtering Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Spectrum of Processed
original image image
92
of
118
Sharpening in the Frequency Domain
0 if D (u , v ) D0
H (u , v )
1 if D (u , v ) D0
where D0 is the cut off distance as before
94
of
118
Ideal High Pass Filters (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
1
H (u , v )
1 [ D0 / D (u , v )] 2n
Results of Results of
Butterworth Butterworth
high pass high pass
filtering of filtering of
order 2 with order 2 with
D0 = 15 D0 = 80
D 2 ( u , v ) / 2 D0 2
H (u , v ) 1 e
where D0 is the cut off distance as before
98
of
118
Gaussian High Pass Filters (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of Results of
Gaussian Gaussian
high pass high pass
filtering with filtering with
D0 = 15 D0 = 80
Results of ideal
high pass filtering
with D0 = 15
100
of
118
Highpass Filter Comparison
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of Butterworth
high pass filtering of order
2 with D0 = 15
101
of
118
Highpass Filter Comparison
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of Gaussian
high pass filtering with
D0 = 15
102
of
118
Highpass Filter Comparison
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of ideal
high pass filtering
with D0 = 15
104
of
118
Highpass Filter Comparison
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of Butterworth
high pass filtering of order
2 with D0 = 15
105
of
118
Highpass Filter Comparison
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Results of Gaussian
high pass filtering with
D0 = 15
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
118
106
High frequency
emphasis result Original image
of
111
118
Inverse DFT of
Laplacian in the Laplacian in the
frequency domain frequency domain
domain
in the frequency
2-D image of Laplacian
spatial filter
left compared to
the image on the
Laplacian In The Frequency Domain
Zoomed section of
112
of
118
Frequency Domain Laplacian Example
Original Laplacian
image filtered
image
Laplacian
Enhanced
image scaled
image
113
of
118
Fast Fourier Transform
The reason that Fourier based techniques have
become so popular is the development of the
Fast Fourier Transform (FFT) algorithm
Allows the Fourier transform to be carried out in
a reasonable amount of time
Reduces the amount of time required to perform
a Fourier transform by a factor of 100 – 600
times!
114
of
Frequency Domain Filtering & Spatial
118 Domain Filtering
Similar jobs can be done in the spatial and
frequency domains
Filtering in the spatial domain can be easier to
understand
Filtering in the frequency domain can be much
faster – especially for large images
Image Processing and Pattern
Recognition (IPPR):
(Lecture 7)