Professional Documents
Culture Documents
CV.2 - Image Enhancement - Restoration (5-6)
CV.2 - Image Enhancement - Restoration (5-6)
Restoration
Computer Vision
CONTENTs
Computer Vision 2
CONTENTs
Computer Vision 3
Image transformations
What types of image transformations can we do?
Warping Filtering
Point
Operation
point processing
Neighborhood
Operation
“filtering”
Computer Vision 5
Point operators
• Reverse Image
• Image Thresholding
• Logarithmic Transformations
• Power-law (Gamma) Transformations
• Contrast Stretching
• Grey level Slicing
• Bit-Plane Slicing
Image Enhancement
Computer Vision 6
…Point operators
Computer Vision
…Point operators
•Image negatives (Reverse Image)
• Cải thiện các chi tiết màu trắng hay màu xám nằm trong vùng tối của ảnh
s = L-1- r = intensitymax - r
Original Negative
s = 1.0 - r
Image Image
Computer Vision
…Point operators
•Image Thresholding
•Hữu ích với phân đoạn ảnh: cô lập một đối tượng so với nền
Computer Vision
…Point operators
Computer Vision
…Point operators
Logarithmic transforms
Biến đổi log ánh xạ vùng hẹp các mức sáng đầu vào thành vùng rộng
các mức sáng đầu ra
Biến đổi log ngược thực hiện chuyển đổi ngược lại
Computer Vision
…Point operators
Logarithmic transforms
•Các hàm log rất hữu ích khi các giá trị độ xám của ảnh đầu vào có
miền giá trị rộng.
s = log(1 + r)
•ví dụ, biến đối Fourier của một ảnh được chuyển sang biến đổi log
để làm rõ hơn các chi tiết.
s = log(1 + r)
Computer Vision
…Point operators
Biến đổi hàm mũ
0.9
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
…Point operators
Biến đổi hàm mũ
γ = 0.4
T ra n s fo rm e d In te n s itie s
1
0.9
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
…Point operators
Biến đổi hàm mũ
γ = 0.3
T ra n s fo rm e d In te n s i ti e s
1
0.9
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
…Point operators
Biến đổi hàm mũ
s = r 0.6
s = r 0.4
r 0 .3
Computer Vision
…Point operators
Biến đổi hàm mũ
…Point operators
Biến đổi hàm mũ
γ = 5.0
T ra n s fo rm ed In ten sities
1
0.9
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
…Point operators
Biến đổi hàm mũ
s = r 3.0
•Ảnh đường băng chụp từ
trên không
s = r 4.0
s=
r
•Biến đổi hàm mũ được sử dụng 5.0
Computer Vision
…Point operators
Computer Vision
…Point operators
Computer Vision
…Point operators
Computer Vision
…Point operators
Bit Plane Slicing
[10000000] [01000000]
[00100000] [00001000]
[00000100] [00000001]
Computer Vision
…Point operators
Bit Plane Slicing
Computer Vision
…Point operators
Bit Plane Slicing
Computer Vision
…Point operators
original darken lower contrast non-linear lower contrast
Computer Vision 28
Histogram equalization
Grey Levels
Computer Vision
…Histogram equalization
Computer Vision
…Histogram equalization
…Histogram equalization
…Histogram equalization
Computer Vision
…Histogram equalization
Computer Vision
…Histogram equalization
Nới rộng tần số trong ảnh (hay cân bằng ảnh) là kỹ thuật đơn giản
để cải thiện ảnh tối hoặc các ảnh rửa trôi
Computer Vision
…Histogram equalization
Computer Vision
…Histogram equalization
Basic reading:
Computer Vision 42
CONTENTs
•Image Filter
• Image Enhancement
• Image Restoration
• Image Pyramids
Computer Vision 43
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
Computer Vision 45
Linear filter
• We can generalize this idea by allowing different weights for different neighboring
pixels:
Computer Vision 46
Linear filter
Cross-correlation filtering (Linear filter)
• We can generalize this idea by allowing different weights for different neighboring
pixels:
a b c r s t eprocessed = v*e +
d e f u v w r*a + s*b + t*c +
g h i x y z u*d + w*f +
Original Image Pixels Filter
x*g + y*h + z*i
Computer Vision 47
…Linear filter
Computer Vision 48
…Linear filter
…More properties
• Commutative: a * b = b * a
• Conceptually no difference between filter and signal
• 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)
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
Computer Vision
…Linear filter
Smoothing with box filter
Computer Vision 52
…Linear filter
…Sharpening
Computer Vision
Convolution filter
It is written: G H *F
a b c r s t eprocessed = v*e +
d e f * u v w z*a + y*b + x*c +
w*d + u*f +
g h i x y z
Original Image Pixels Filter
t*g+ s*h + r*i
Computer Vision 54
…Convolution filter
• 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.
Computer Vision 55
…Convolution filter
Computer Vision 56
CONTENTs
•Image Enhancement
• Image Restoration
• Image Pyramids
Computer Vision 57
Gaussian filter
Computer Vision 58
…Gaussian filter
“fuzzy blob”
kernel
Important filter: Gaussian filter 1 2 1
1
A Gaussian kernel gives less weight to pixels further 2 4 2
16
from the center of the window 1 2 1
Computer Vision 59
…Gaussian filter
• Gaussian Kernel
5 x 5, = 1
Computer Vision 60
…Gaussian filter
Gaussian filter
vs. Box filter
…Gaussian filter
Gaussian vs Box filtering
7x7 Gaussian
original
Computer Vision 64
Derivative filter
Very sharp
discontinuities
in intensity.
grayscale image
domain
Computer Vision 65
… Derivative filter
Edge detection
Goal: Identify sudden changes (discontinuities) in an image
Computer Vision 66
… Derivative filter
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
Computer Vision 67
… Derivative filter
Finite differences
• Definition of the first-order derivative using forward difference
Computer Vision 68
… Derivative filter
8
Finite differences 7
6
f(x)
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
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
của hàm -4
-6
-8
Computer Vision 69
… Derivative filter
8
Finite differences 7
6
f(x)
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
2nd 0 0 1
Derivative 1 -4 1 1 0 0 7 -7 0 0
10
5 f’’(x)
0
-15
Computer Vision 70
… Derivative filter
Finite differences
Computer Vision 71
… Derivative filter
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
Computer Vision 72
… Derivative filter
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.
Computer Vision 73
… Derivative filter
Image gradient
• The gradient of an image:
• Amplitude
Computer Vision 74
… Derivative filter
Image gradient
vertical
original
derivative
gradient horizontal
amplitude derivative
Computer Vision 75
… Derivative filter
Effects of noise
• Consider a single row or column of the image
• Plotting intensity as a function of position gives a signal
(Intensity)
(derivative)
Where is the edge?
Computer Vision 76
… Derivative filter
Computer Vision 77
… Derivative filter
Solution: blur/smooth first
input
Gaussian g
blurred f*g
derivative of
( f g) How much
blurred x
should we blur?
( f g)
x
Computer Vision To find edges, look for peaks in 78
… Derivative filter
input
f
derivative of
h
Gaussian x
output (same as
before) ( h) f
x
Computer Vision 79
… Derivative filter
* [1 0 -1] =
Computer Vision 80
… Derivative filter
x-direction y-direction
Computer Vision 81
Laplace filter
2 f
2
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y
Computer Vision 82
…Laplace filter
• 2
f [ f ( x 1, y ) f ( x 1, y )
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
Computer Vision 83
…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
2
g ( x, y ) f ( x, y ) f
- =
Original Laplacian Sharpened
Image Filtered Image Image
Computer Vision 84
…Laplace filter
Computer Vision 85
…Laplace filter
Computer Vision 86
…Laplace filter
0 -1 0
-1 5 -1
0 -1 0
Computer Vision 87
…Laplace filter
-1 -1 -1
-1 9 -1
-1 -1 -1
Computer Vision 88
…Laplace filter
input
Gaussian
blurred
Computer Vision 89
…Laplace filter
• Derivative of Gaussian filter (DoG)
Derivative theorem of convolution:
input
derivative of
Gaussian
input
Laplacian of
Gaussian
Computer Vision 91
…Laplace filter
Gaussian
Derivative of Gaussian
Laplacian of Gaussian
Computer Vision 95
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
• a 2D separable filter is equivalent to two 1D convolutions
(with the “column” and “row” filters).
• If the image has M x M pixels and the filter kernel has size N x N:
• What is the cost of convolution with a non-separable filter? M2 x N2
• What is the cost of convolution with a separable filter? 2 x N x M2
Computer Vision 96
…Sobel filter
2D convolution
(center location only)
Perform convolution
along rows
Followed by convolution
along the remaining column
Computer Vision
…Sobel filter
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
Computer Vision 98
…Sobel filter
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
Computer Vision 99
…Sobel filter
1 0 -1
2 0 -2
1 0 -1
Horizontal Sober filter
Vertical Edge
(absolute value)
Computer Vision
…Sobel filter
1 2 1
0 0 0
-1 -2 -1
Vertical Sobel filter:
Horizontal Edge
(absolute value)
Computer Vision
Image Filter
Basic reading:
•Image Restoration
• Image Pyramids
Noise
• Nhiễu xuất hiện trong quá trình thu nhận ảnh, số hóa và truyền
• Cảm biến ảnh có thể bị ảnh hưởng bởi các điều kiện môi trường
• Nhiễu có thể can thiệp vào ảnh trong quá trình truyền
• Ảnh nhiễu được mô phỏng như sau:
g ( x, y ) f ( x , y ) ( x , y )
f(x, y) là ảnh ban đầu
η(x, y) là nhiễu
g(x, y) ảnh sau khi bị nhiễu tác động
Nếu xác định mô hình nhiễu, ta có thể tách nhiễu để phục hồi ảnh
Computer Vision
Image Restoration
Common Types of Noise
Gaussian noise: variations in intensity drawn from a
Gaussian normal distribution
Image Histogram
Histogram to go here
Computer Vision
nhiễu với các mô hình khác nhau
Image Restoration
Mô hình nhiễu
nhiều mô hình nhiễu
η(x, y) khác nhau:
• Gaussian
thông dụng
• Rayleigh
• Erlang
• Hàm mũ
• Đồng nhất
• Xung
Nhiễu muối,
nhiễu hạt tiêu
Computer Vision
Image Restoration
• Dùng lọc không gian đơn giản để loại nhiễu:
• Trung bình số học
• Trung bình hình học
• Trung bình Harmonic
• Trung bình Contraharmonic
ˆ 1
f ( x, y ) g ( s, t )
mn ( s ,t )S xy /9
1 1
/9 /9
1
/9
1 1
/9 /9
1
Computer Vision
Image Restoration
Làm việc tốt với nhiễu muối nhưng không tốt với nhiễu hạt tiêu
Computer Vision
Image Restoration
g ( s, t ) Q 1
fˆ ( x, y )
( s ,t )S xy
g ( s ,
( s ,t )S xy
t ) Q
Q là bậc của bộ lọc; thay đổi Q sẽ làm thay đổi hành vi của bộ lọc
Q >0 loại nhiễu hạt tiêu
Q <0 loại nhiễu muối
Computer Vision
Image Restoration
Image
Corrupted
Original By Gaussian
Image Noise
Image Image
Corrupted Corrupted
By Pepper By Salt
Noise Noise
Result of
Result of Filtering Above
Filtering Above With 3*3
With 3*3 Contraharmonic
Contraharmonic Q=-1.5
Q=1.5
Image Restoration
Chọn không đúng giá trị của Q khi sử dụng lọc contraharmonic
có thể mạng lại những kết quả không mong muốn
Computer Vision
Image Restoration
• Dùng lọc không gian dựa trên giá trị pixel lân cận của bộ lọc (lọc thống kê)
• Lọc trung vị
• Lọc Max, Min
• Lọc Midpoint
• Lọc cắt Alpha
• Lọc trung vị
fˆ ( x, y ) median{g ( s, t )}
( s ,t )S xy
không gây hiệu ứng làm mịn ảnh như các lọc trung bình,
Tốt cho lọc nhiễu muối và hạt tiêu
Computer Vision
Image Restoration
• Lọc Max
fˆ ( x, y ) max {g ( s, t )}
( s ,t )S xy
• Lọc Min
fˆ ( x, y ) min {g ( s, t )}
( s ,t )S xy
Computer Vision
Image Restoration
• Lọc Midpoint
1
f ( x, y ) max { g ( s, t )} min { g ( s, t )}
ˆ
2 ( s ,t )S xy ( s ,t )S xy
Tốt loại bỏ nhiễu Gaussian và nhiễu đồng nhất
• Alpha-Trimmed
1
fˆ ( x, y ) g r ( s, t )
mn d ( s ,t )S xy
loại bỏ d/2 mức xám lớn nhất và d/2 mức xám bé nhất
gr(s, t) biễu diễn phần còn lại của mn – d pixels
Computer Vision
Image Restoration
Image Result of 1
Corrupted Pass With A
By Salt And 3*3 Median
Pepper Noise Filter
Result of 2 Result of 3
Passes With Passes With
A 3*3 Median A 3*3 Median
Filter Filter
Image Restoration
Image Image
Corrupted Corrupted
By Pepper By Salt
Noise Noise
Result Of Result Of
Filtering Filtering
Above Above
With A 3*3 With A 3*3
Max Filter Min Filter
Image Restoration
Filtered By Filtered By
5*5 Arithmetic 5*5 Geometric
Mean Filter Mean Filter
Filtered By Filtered By
5*5 Median 5*5 Alpha-Trimmed
Filter Mean Filter
CONTENTs
•Image Pyramids
Computer Vision 123
Image downsampling
• Why does a lower resolution image still make sense to us? What do we lose?
1/8
1/4
Computer Vision
…Image downsampling
Undersampling
Computer Vision
…Image downsampling
Undersampling
v v v good
bad
Computer Vision
Gaussian image pyramid
Algorithm sample
repeat:
filter
filter
sample
subsample
filter
until min resolution reached
sample
Question: How much bigger than the original image is the whole pyramid?
Answer: Just 4/3 times the size of the original image!
Computer Vision
…Gaussian image pyramid
Computer Vision
Laplacian image pyramid
Blurring is lossy
- =
Computer Vision
…Laplacian image pyramid
= +
Does this mean we need to store both residuals and the blurred copies of the original?
Computer Vision
…Laplacian image pyramid
Algorithm
repeat:
filter
compute residual
subsample
until min resolution reached
Computer Vision
…Laplacian image pyramid
It’s a Gaussian
pyramid.
Algorithm
repeat:
filter
compute residual
subsample
until min resolution reached
Computer Vision
…Laplacian image pyramid
What do we need to construct the original image?
Computer Vision
…Laplacian image pyramid
What do we need to construct the original image?
(2) smallest
image
(1) residuals
Computer Vision
…Laplacian image pyramid
Reconstructing the original image
Algorithm
repeat:
upsample
Computer Vision
Gaussian vs Laplacian Pyramid
Shown in opposite
order for space.
- =
Computer Vision
Image Filter
Basic reading:
Thank You…!
Computer Vision 152