Professional Documents
Culture Documents
IP.03-Image Enhancement-b.Spatial Filters
IP.03-Image Enhancement-b.Spatial Filters
IP.03-Image Enhancement-b.Spatial Filters
Lecturer: LeNga
Image filter
• Image filtering
• Compute function of local neighborhood at each position
• Replace each pixel with a weighted average of its neighborhood
• The weights are called the filter kernel
• Really important!
• Enhance images g[ , ]
• Denoise, resize, increase contrast, etc.
1 1 1
• Extract information from images
• Texture, edges, distinctive points, etc. 1 1 1
• Detect patterns
• Template matching 1 1 1
• Linear filter
Image filters
in the spatial domain • Convolution filter
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 5
Linear filter
Cross-correlation filtering
• Let’s write this down as an equation. Assume the averaging window is
(2k+1)x(2k+1):
1 1 1
1 1 1
1 1 1
Example: the box filter- the 2D rect filter also known as the square mean filter
• Replaces each pixel with an average of
1 1 1
its neighborhood
1 1 1 1
H ( x, y ) .
• Achieve smoothing (blurring) effect 9 1 1 1
(remove sharp features) kernel
Digital Image Processing 8
…Linear filter
H ( x, y )
Origin
F ( x, y ) 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 Pixels
e
Neighbourhood
3*3 Filter
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y
x*g + y*h + z*i
kernel 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 0 90 90 90 0 0
1 1 1 0 0 0 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 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
shift-invariant:
1 1 1
1 1 1 0 0 0 90 90 90 90 90 0 0
as the pixel
0 0 0 0 0 0 0 0 0 0 shifts, so does
0 0 0 0 0 0 0 0 0 0 the kernel
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 0 90 90 90 0 0
1 1 1 0 0 0 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 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 0 90 90 90 0 0
1 1 1 0 0 0 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 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 90 90 90 90 0 0
1 1 1 0 0 0 90 0 90 90 90 0 0
1 1 1 0 0 0 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 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
1 1 1 0 0 0 90 90 90 90 90 0 0 0 30
1 1 1 0 0 0 90 0 90 90 90 0 0
1 1 1 0 0 0 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 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
1 1 1 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 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 0 10 20 30 30 30 20 10
0 0 0 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0
0 0 90 0 0 0 0 0 0 0 10
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
1 1 1 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 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 0 10 20 30 30 30 20 10
0 0 0 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0
0 0 90 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0
0 0 0 0 0 0 0 0 0 0
kernel 0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
1 1 1 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1 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 0 10 20 30 30 30 20 10
0 0 0 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0
0 0 90 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0
0 0 0 0 0 0 0 0 0 0
• Ở biên:
O x
e e
e
e
e e e
y Ảnh f(x,y)
0 0 0
0 1 0
0 0 0
0 0 0
0 0 1
0 0 0
1 1 1
1 1 1
1 1 1
-
0 0 0 1 1 1
0 2 0 1 1 1
0 0 0 1 1 1
Sharpening filter
Original - accentuates differences with local average
- stress intensity peaks
Digital Image Processing
…Linear filter
• Associative: a * (b * c) = (a * b) * c
• Often apply several filters one after another: (((a * b1) * b2) * b3)
• This is equivalent to applying one filter: a * (b1 * b2 * b3)
• Linear filter
Image filters
in the spatial domain • Convolution filter
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 34
Convolution filter
It is written:
G H *F
a b c r s t eprocessed = v*e +
z*a + y*b + x*c +
d
g
e
h
f
i
* u
x
v
y
w
z
w*d + u*f +
t*g+ s*h + r*i
Original Image Filter
Pixels
• 2D linear filter
• 2D convolution filter
• Most of the time won’t matter, because our kernels will be symmetric.
• Will be important when we discuss frequency-domain filtering.
Digital Image Processing 37
…Convolution filter
• Linear filter
Image filters
• Convolution filter
in the spatial domain
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 39
Gaussian filter
• Gaussian Kernel
5 x 5, = 1
Digital Image Processing 42
…Gaussian filter
Gaussian filter
vs. Box filter
…Gaussian filter
Gaussian vs Box filtering
7x7 Gaussian
original
• Linear filter
Image filters
• Convolution filter
in the spatial domain
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 47
Derivative filter
Very sharp
discontinuities
in intensity.
grayscale image
domain
Edge detection
Goal: Identify sudden changes (discontinuities) in an image
Characterizing edges
• An edge is a place of rapid change in the image intensity function
intensity function
image (along horizontal scanline) first derivative
edges correspond to
extrema of derivative
Finite differences
• Definition of the first-order derivative using forward difference
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
1st Derivative
0 -1 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
8
6
4
f’(x)
sự khác nhau của các giá 2
8
Finite differences 7
f(x)
6
5
4
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
2nd0 0 1
Derivative 1 -4 1 1 0 0 7 -7 0 0
10
5 f’’(x)
0
-15
Finite differences
1 0 -1 1 2 1 3 0 -3 3 10 3
Sobel 2 0 -2 0 0 0 Scharr 10 0 -10 0 0 0
1 0 -1 -1 -2 -1 3 0 -3 -3 -10 -3
1 0 -1 1 1 1
0 1 1 0
Prewitt 1 0 -1 0 0 0 Roberts
-1 0 0 -1
1 0 -1 -1 -1 -1
Image gradient
• The gradient of an image:
1 0 -1 1 2 1
2 0 -2 0 0 0
1 0 -1 -1 -2 -1
• Convolve with the image to compute derivatives.
Image gradient
• The gradient of an image:
• Amplitude
vertical
original
derivative
gradient horizontal
amplitude derivative
Effects of noise
• Consider a single row or column of the image
• Plotting intensity as a function of position gives a signal
(Intensity)
input
Gaussian g
blurred f*g
derivative of
( f g) How much
blurred x
should we blur?
To find edges, look for peaks in x ( f g )
Digital Image Processing 61
… Derivative filter
input
f
derivative of
Gaussian h
x
output (same
as before) ( h) f
x
* [1 0 -1] =
x-direction y-direction
• Linear filter
Image filters
• Convolution filter
in the spatial domain
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 65
Laplace filter
2
f 2
f
f 2 2
2
x y
• Trong đó đạo hàm thành phần bậc 1 theo phương x, y:
f
2
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
• f [ f ( x 1, y) f ( x 1, y)
2
f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
• 0 1 0
1 -4 1
0 1 0
Original Laplacian
Image Filtered Image
Digital Image Processing 67
…Laplace filter
• Kết quả của lọc Laplacian chưa phải là một ảnh cải thiện
Trừ ảnh ban đầu cho ảnh Laplacian để được ảnh cải thiện sắc nét
g ( x, y) f ( x, y) f
2
- =
Original Laplacian Sharpened
Image Filtered Image Image
Digital Image Processing 68
…Laplace filter
f ( x, y ) [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)
4 f ( x, y )]
0 -1 0
5 f ( x, y ) f ( x 1, y ) f ( x 1, y )
-1 5 -1
f ( x, y 1) f ( x, y 1)
0 -1 0
0 -1 0
-1 5 -1
0 -1 0
-1 -1 -1
-1 9 -1
-1 -1 -1
input
Gaussian
blurred
input
derivative of
Gaussian
input
Laplacian of
Gaussian
zero-crossing peak
Gaussian
Derivative of Gaussian
Laplacian of Gaussian
Digital Image Processing 79
Image filter
• Linear filter
Image filters
• Convolution filter
in the spatial domain
• Gaussian filter
• Derivative filter
• Laplace filter
• Sobel filter
Digital Image Processing 80
Sobel filter
Separable filters
• a 2D filter is separable if it can be written as the product of a “column” and a “row”.
1 1 1 1 1 1 1
example: =
box filter
1 1 1 1 * row
1 1 1 1
column
2D convolution
(center location only)
Perform convolution
along rows
Followed by convolution
along the remaining column
1 0 -1 1 1 0 -1
2 0 -2 = 2 * 1D derivative
1 0 -1 1 filter
Sobel filter Blurring
Các bộ lọc Sobel thường được sử dụng để phát hiện nếp gấp
1 0 -1 1
2 0 -2 = 2 * 1 0 -1
1 0 -1 1
1 2 1 1
1 2 1
0 0 0 = 0 *
-1 -2 -1 -1
1 0 -1
2 0 -2
1 0 -1
Horizontal Sober filter
Vertical Edge
(absolute value)
Digital Image Processing
…Sobel filter
1 2 1
0 0 0
-1 -2 -1
Vertical Sobel filter:
Horizontal Edge
(absolute value)
Digital Image Processing
…Sobel filter
example
example
original
(a)
Lọc (b)
Laplacian
Lọc sắc nét (c)
(a)
bằng
Lọc Sobel (a)
cách lấy (d)
(a) trừ (b)
Lọc trung bình
làm mịn (d)
…Lọc trong miền không gian - kết hợp
(h)
Áp dụng
Làm sắc nét chuyển đổi
bằng cách tính hàm mũ (g)
tổng(a) và (f) (g)
(a)
…Lọc trong miền không gian - kết hợp
• So sánh ảnh gốc và ảnh kết quả sau cùng
(a) (h)
Thank You…!