Lecture Week 2A 2018 PDF
Lecture Week 2A 2018 PDF
Lecture Week 2A 2018 PDF
Computer Vision
Image Processing: Basics
Dr Shaodi You
1. Data61 - CSIRO
2. Research School of Engineering, The Australian National University
Review:
The computer vision problem
• Make a computer see and understand images
A person/
A person with
folded arms/
Prof. Pietro
Perona/ etc.
Camera Obscura
3
Slide Credit: Saverese
Projection matrix
R,T
jw
kw
Ow
iw
x KR t X
x: Image Coordinates: (u,v,1)
K: Intrinsic Matrix (3x3)
R: Rotation (3x3)
t: Translation (3x1)
Extrinsic Matrix X: World Coordinates: (X,Y,Z,1)
4
Human visual processing
6
Image processing operations
• Point-wise operations
o histogram operation
• Neighborhood operations
• Spatial domain (image convolution)
o Frequency domain (Fourier transform)
o Binary image analysis
• Geometric operations
o Rotation, translation, affine…
7
Recall: digital image representation
0.92 0.93 0.94 0.97 0.62 0.37 0.85 0.97 0.93 0.92 0.99
0.95 0.89 0.82 0.89 0.56 0.31 0.75 0.92 0.81 0.95 0.91
0.89 0.72 0.51 0.55 0.51 0.42 0.57 0.41 0.49 0.91 0.92
0.96 0.95 0.88 0.94 0.56 0.46 0.91 0.87 0.90 0.97 0.95
0.71 0.81 0.81 0.87 0.57 0.37 0.80 0.88 0.89 0.79 0.85
0.49 0.62 0.60 0.58 0.50 0.60 0.58 0.50 0.61 0.45 0.33
0.86 0.84 0.74 0.58 0.51 0.39 0.73 0.92 0.91 0.49 0.74
0.96 0.67 0.54 0.85 0.48 0.37 0.88 0.90 0.94 0.82 0.93
0.69 0.49 0.56 0.66 0.43 0.42 0.77 0.73 0.71 0.90 0.99
0.79 0.73 0.90 0.67 0.33 0.61 0.69 0.79 0.73 0.93 0.97
0.91 0.94 0.89 0.49 0.41 0.78 0.78 0.77 0.89 0.99 0.93
8
I = f(x,y): R2 R (grey image);
or R2 R3 (colour image)
Origin
y
Image “After snow storm” f(x,y)
9
I = f(x,y)
10
Point Operations
Operation on Pixel's
value
Context free
Operation can be
performed on the image
histogram
Example:
g x, y M f x, y
g x, y f x, y
11
Neighbourhood Operations
Operation depends on
Pixel's value and its
spatial neighbours.
Context dependant.
g x, y M f i, j | (i, j ) N x, y
Example:
g x, y f i, j / n
i , jN ( x , y )
12
Geometric Operations
Operation depend on
pixel's coordinates.
Independent of pixels
value.
Example: translation
g x, y f x a, y b
13
Point operations:
(Histogram operation)
14
Point Operations
M v v
• In other words,
Pr(R rk ) p(rk )
17
Some Typical Histograms
The shape of a histogram provides useful information for
image global appearance.
Dark image
18
Bright image
Low-contrast image
19
High-contrast image
20
Application: image enhancement
21
Histogram-based image
enhancement/image editing
• Histogram modification
• Histogram Equalization
• Histogram Matching
22
Histogram modification
vb M v a
• M(va) takes any value va in image A and maps it into vb in
image B.
• Requirement: the mapping M is a non descending function
(M-1 exists).
• In this case, the area under Ha between 0 and va is equal to the
area under Hb between 0 and vb.
23
Monotonicity Requirement
• If it is required to map the full gray-level range (256
values) to its full range while keeping the gray-level
order, a non-decreasing monotonic mapping
function is needed:
M(v)
255
stretching
v
255
contraction 24
• The area under Ha between 0 and va is equal to the
area under Hb between 0 and vb=M(va)
v
M(v)
v
Hb
Ha
v
25
Contrast Enhancement
• If most of the gray-levels in the image are in
[u1 u2], the following mapping increases the
image contrast.
• The values u1 and u2 can be found by using
the image’s accumulated histogram.
255
M(v)
u1 u2 v
255 26
Power-law transformations
s cr
27
28
Histogram Equalization
• Visual contrast between objects depends on the their
gray-level separation.
• How can we improve the contrast after an image has
been acquired?
29
Histogram Equalization
31
Histogram equalized image and its histogram
32
Hist. Eq.: Example 1
3500 3500
3000 3000
2500 2500
2000 2000
1500 1500
1000 1000
500 500
0 0
0 50 100 150 200 250 0 50 100 150 200 250
33
Original Equalized
Hist. Eq.: Example 2
3000
3000
2500
2500
2000
2000
1500
1500
1000
1000
500
500
0
0 0 50 100 150 200 250
0 50 100 150 200 250
Original Equalized 34
Comments:
Histogram equalization may not always produce desirable
results, particularly if the given histogram is very narrow. It
can produce false edges and regions. It can also increase
image “graininess” and “patchiness.”
35
36
Histogram Matching
• Histogram matching is a process where an image is
modified such that its histogram matches that of another
(reference) image.
38
2D Geometric Transformations
39
Image Warping
http://www.jeffrey-martin.com
40
Some slides from Steve Seitz
Image Warping
Point operation and neighborhood operation:
change range of image
g(x) = h(f(x))
f f
h
x x
f g
h
42
Image Warping
Why?
- texture mapping
- image morphing/blending
43
Geometric transformation
Examples of transformation
47
Types of Image Warping
Simple geometric transformations:
- Rotation;
- Similarity
- Affine mapping
- Projective mapping
48
Types of Transformation
2
50
Scaling
• Non-uniform scaling: different scalars per
component:
x’=x 2;
y’=y0.5
51
Scaling
a=1/2
x' a 0 x
y ' 0 1 / a y
53
53
Rotation
y
y’
x’
θ
x
54
54
Rotation Example
θ=3o
55
55
Shear
square parallelogram
x' 1 0 x d x
y ' s 1 y d
y
56
56
Shear Example
x ' 1 0 x 0
y ' .5 1 y 1
57
57
Affine Transform:
Rotation+Scaling+Sheer+Translation
square parallelogram
59
59
Projective Transform
B’
A B
A’
C’
D C
D’
square quadrilateral
a1 x a2 y a3
x '
a7 x a8 y 1
a 4 x a5 y a 6
y'
a7 x a8 y 1
60
60
Projective Transform Example
61
61
Projective Image stitching
62
62
How to compute image warping ?
63
Image Warping Computation
x u
y v
S(x,y) T(u,v)
64
Forward Warping
x u
y v
S(x,y) T(u,v)
y v
S(x,y) T(u,v)
y v
S(x,y) T(u,v)
67
Forward Warping
x u
y v
S(x,y) T(u,v)
y v
for y = ymin to ymax
for x = xmin to xmax
u = f(x,y); v = g(x,y)
copy pixel at source S(x,y) to T(u,v)
69
Forward Warping
• Iterate over source, sending pixels to destination
• Some source pixels map to the same dest. pixels
• Some dest. pixels may have no corresponding
source
• Holes in reconstruction - How to remove the holes?
y v
for y = ymin to ymax
for x = xmin to xmax
u = f(x,y); v = g(x,y)
copy pixel at source S(x,y) to T(u,v)
70
Forward Warping
• Iterate over source, sending pixels to destination
• Some source pixels map to the same dest. pixels
• Some dest. pixels may have no corresponding
source
• Holes in reconstruction - How to remove the holes?
y v
for y = ymin to ymax
for x = xmin to xmax
u = f(x,y); v = g(x,y)
copy pixel at source S(x,y) to T(u,v)
71
Inverse Warping
x u
y v
S(x,y) T(u,v)
y v
S(x,y) T(u,v)
73
Inverse Warping
• Iterate over dest., finding pixels from source
• Non-integer evaluation source image, resample
• May oversample source
• But no holes
• Simpler, better than forward mapping
x u
74
Forward vs. inverse warping
• Q: which is better?
75
2D Geometric Transformations in
Homogeneous Coordinates Representation
76
Homogeneous Coordinates
• Homogeneous
coordinates
– represent coordinates
in 2 dimensions with a
3-vector
x
x homogeneous coords
y y
1
77
Homogeneous Coordinates
x' x t x
y' y t y
78
Homogeneous Coordinates
x ' x t x 1 0 tx x
y ' y t 0 1
t y y
y
1 1 0 0 1 1
79
Translation
Homogeneous Coordinates
• Example of
translation
x' 1 tx x x tx
0
y '
0 1 t y y y t
y
1 0 0
1 1 1
tx = 2
ty = 1
80
Basic 2D Transformations in homogeneous
representation
x ' 1 0 t x x x ' s x 0 0 x
y ' 0 1 t y y ' 0 sy 0 y
y
1 0 0 1 1 1 0 0 1 1
Translate Scale
Rotate Shear
81
Affine Transformations
83
Projective Transformations
a1 x a2 y a3
x '
• Projective transformations … a7 x a8 y 1
a 4 x a5 y a 6
– Affine transformations, and y'
a7 x a8 y 1
– Projective warps
• Properties of projective transformations:
– Origin does not necessarily map to origin
– Lines map to lines
– Parallel lines do not necessarily remain parallel
– Ratios are not preserved
– Closed under composition x' a b c x
y ' d e f y
– Models change of basis w' g h i w
84
Hierarchy of 2D image transformations
(stratification)
http://astronomy.swin.edu.au/~pbourke/projection/imagewarp/
86
86
Free Form Warping
87
87
Image Morphing
88
Image morphing
image #1 cross-fading image #2
89
Summary
• Point operation and histogram equalization
can enhance the image contrast
• Geometrical transformation is used in
image wrapping
• Read textbook Section 3.1 & Section 3.6.