Lect 1
Lect 1
noise reduction
3x3
median
filter
Preview 2
edge enhancement
detail
Preview 3
Contrast enhancement
Preview 4
deblurring
detail
Preview 5
• Also excellent
Lecture 1: Image Enhancement
• Image basics
• Two types of quantization
• Point operations
• Histogram equalization
• Temporal averaging
(0,0)
84 133 226 212 218 218 222 212 218 222 226 218
75 156 177 218 212 218 218 218 218 222 218 218
96 84 133 203 218 218 218 222 212 218 222 218
123 75 111 156 212 218 212 212 218 218 218 226
93 75 71 133 185 231 226 226 222 212 218 218
51 75 75 75 156 206 218 218 218 222 212 222
44 110 75 65 143 194 231 218 218 218 218 218
52 123 69 84 60 156 199 231 231 222 226 226
52 75 84 81 65 69 150 231 231 226 231 231
36 36 84 93 84 71 156 160 240 240 231 231
36 40 113 75 69 75 71 133 194 240 240 240
52 52 105 85 69 75 75 123 111 222 231 231
69 44 69 93 81 75 75 69 150 177 247 240
73 44 40 96 101 75 75 75 84 133 231 240
Intensity Quantization
92 x 72 pixels 48 x 36 pixels
Colour Sensing in Camera (RGB)
3-chip vs. 1-chip: quality vs. cost
http://www.cooldictionary.com/words/Bayer-filter.wikipedia
Slide by Steve Seitz
Practical Colour Sensing: Bayer Grid
Estimate RGB
at ‘G’ cells from
neighbouring values
http://www.cooldictionary.com/
words/Bayer-filter.wikipedia
Slide by Steve Seitz
Image statistics
Quantization:
• Often 8 bits per pixel (0-255, 28 = 256 levels) for monochrome
• 24 bits per pixel for colour (8 bits for each of Red Green Blue)
• Medical images 12 bits (4096 levels) or 16 bits (65536 levels)
Size
• Cameras typically 4K x 3K pixels or far more
• Satellite images 10 -100K pixels width
• 3D images
• e.g. Magnetic Resonance Images
• Videos (2D + time)
Shanghai Skyline - Stitched from 12,000 photos
273 G pixels
http://gigapan.com/
Google Art Project
Examples
• How to improve contrast?
in = function(i)
new original
intensity intensity
i
Point operations – Negative
Point operations – power-law transformations
1.00
in = iγ
0.75
in
0.50
0.25
original γ=3
γ=4 γ=5
Contrast Stretching
Image Histograms
Cumulative Histograms
s = T(r)
Histogram equalization (or flattening)
new
original
frequency
original goal
histogram
intensity
• use cumulative distribution as a measure
cumulative
Flattening map
original goal
N N
i in
N
in i Proof: exercise
Algorithm:
20
80
5
10
40
100 frames
0 frames
frames
new original
intensity intensity
Image filtering
• Many applications:
– Enhance images
• Denoise, resize, increase contrast, etc.
– Extract information from images
• Texture, edges, distinctive points, etc.
– Detect patterns
• Template matching
Image filtering 1 1 1
h[ , ] 1 1 1
1 1 1
f [.,.] g[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
g[m, n] h[k , l ] f [m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
h[ , ] 1 1 1
1 1 1
f [.,.] g[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
?
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0 50
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
g[m, n] h[k , l ] f [m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
h[ , ] 1 1 1
1 1 1
f [.,.] g[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
g[m, n] h[k , l ] f [m k , n l ]
k ,l Credit: S. Seitz
Box Filter
1 1 1
• Achieve smoothing effect
(remove sharp features)
0 0 0
0 1 0 ?
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 0 1 ?
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0 1 1 1
0
0
2
0
0
0
- 1
1
1
1
1
1
?
(Note that filter sums to 1)
Original
Source: D. Lowe
Sharpening
Source: D. Lowe
Other filters
1 0 -1
2 0 -2
1 0 -1
Sobel
Vertical Edge
(absolute value)
Other filters
1 2 1
0 0 0
-1 -2 -1
Sobel
Horizontal Edge
(absolute value)
Rectangular filter
=
*
h[m,n]
f[m,n] g[m,n]
Rectangular filter
=
*
h[m,n]
f[m,n] g[m,n]
Properties of linear filters
• Use ∗ for the action of the filter
• Linear filtering is a linear operation
• e.g. filtering the sum of two signals produces the same result
as filtering each signal individually and summing the result
• and is shift invariant, e.g. shift the input image two pixels to
the left, then the output is shifted two pixels to the left
• We will see later:
• the connection between filters and convolution
• non-linear filters
Gaussian noise
f(x)
f(x) + n(x)
small large
e.g. if = 1, k = 3
f(x) + n(x)
G(x,y) * f(x,y)
Gaussian filter = 2
6
Gaussian filter = 4 6
Gaussian smoothing
Matlab
>> hsize = 10;
>> sigma = 5;
>> h = fspecial(‘gaussian’ hsize, sigma);
>> mesh(h);
>> imagesc(h);
outim
Example
2D filtering
(centre location only)
Perform filtering =
along rows: *
Followed by filtering =
along the remaining column: *
Source: K. Grauman
Separability example
*
=
gv * gh * f = (gv * gh) * f
= =
*
What is the computational
complexity advantage for a
separable filter of size k x k,
in terms of number of
= gv * (gh * f)
operations per output pixel?
Summary
1 1 1
Linear filtering is a weighted sum/difference of 1 1 1
pixel values 1 1 1
g = filter2( h, f );
h=filter f=image
e.g. h = fspecial('gaussian');
How to determine the action of a filter
f [.,.]
1
1
1
1
1
1
g[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
f
h
vector f vector h
• g is max when f and h are parallel
• maximum response when filter matches signal
Template matching example
• Goal: find in image
True detections
False
detections
(h[k , l ] h )( f [m k , n l ] f m,n )
g[m, n] k ,l
0.5
2
(h[k , l ] h ) ( f [m k , n l ] f m ,n )
2
k ,l k ,l
True detections