ECE661 Computer Vision HW 3

ECE661 Computer Vision HW 3
Rih-Teng Wu
Email: [email protected]
1. Remove Projective Distortion โ€“ Point to Point Correspondence
When we see the parallel lines in the world plane are not parallel in an image,
there exists the projective distortion in the image. To remove the projective
distortion, we can use the homography calculated by means of point to point
correspondence. According to what we have learned from HW2, the mapping
between an image plane and a world plane is given by:
๐‘‹๐‘‹๐‘–๐‘– = ๐ป๐ป๐‘‹๐‘‹๐‘ค๐‘ค
Where ๐‘‹๐‘‹๐‘–๐‘– is the points of image plane in homogeneous coordinates, ๐‘‹๐‘‹๐‘ค๐‘ค is the
points of world plane in homogeneous coordinates, and ๐ป๐ป is the homography matrix.
h11
x
xโ€ฒ
Now, let ๐‘‹๐‘‹๐‘–๐‘– = ๏ฟฝyโ€ฒ๏ฟฝ , ๐‘‹๐‘‹๐‘ค๐‘ค = ๏ฟฝy๏ฟฝ, and ๐ป๐ป = ๏ฟฝh21
1
h31
1
h12
h22
h32
h13
h23 ๏ฟฝ. Since we only care about ratios
h33
in homogeneous representation, the value of h33 can be set to 1. To solve the eight
unknowns, we need to find at least four pairs of corresponding points in the image
plane and the world plane. As a result, if now we have ๐‘›๐‘› pairs of corresponding
points, and denote the ๐‘–๐‘– ๐‘ก๐‘กโ„Ž pair of corresponding points as (xi โ€ฒ , yi โ€ฒ ), (xi , yi ) , we have the
following relation:
xi โ€ฒ = xi h11 + yi h12 + h13 โˆ’ xi โ€ฒ xi h31 โˆ’ xi โ€ฒ yi h32
yi โ€ฒ = xi h21 + yi h22 + h23 โˆ’ yi โ€ฒ xi h31 โˆ’ yi โ€ฒ yi h32
Rewrite the above relation in matrix form, we have:
x
โŽก 1
โŽข0
โŽข
โŽขxn
โŽฃ0
y1 1
0 0
โ‹ฎ
yn 1
0 0
0
x1
0
xn
0
y1
โ‹ฎ
0
yn
h11
โŽกh โŽค
โŽข 12 โŽฅ
x1 โ€ฒ
0 โˆ’x1 โ€ฒ x1 โˆ’x1 โ€ฒ y1
h
โŽค
โŽก
โŽค
13
โŽข โŽฅ
1 โˆ’y1 โ€ฒ x1 โˆ’y1 โ€ฒ y1
y1 โ€ฒ โŽฅ
โŽฅ
h
โŽข
× โŽข 21 โŽฅ
=โŽข โ‹ฎ โŽฅ
โ‹ฎ
โŽฅ
โ€ฒ
โ€ฒ
โ€ฒ
โŽขh22 โŽฅ
0 โˆ’xn xn โˆ’xn yn โŽฅ
โŽขxn โŽฅ
h
23
1 โˆ’yn โ€ฒ xn โˆ’yn โ€ฒ yn โŽฆ2nx8 โŽข โŽฅ
โŽฃyn โ€ฒ โŽฆ2nx1
h
โŽข 31 โŽฅ
โŽฃh32 โŽฆ8x1
Denote the above equation as ๐ด๐ดโ„Ž = ๐ต๐ต, then โ„Ž can be solved using the least
square estimate method just in case we have more than four pairs of corresponding
points.
โ„Ž = (๐ด๐ด๐‘‡๐‘‡ ๐ด๐ด)โˆ’1 ๐ด๐ด๐‘‡๐‘‡ ๐ต๐ต
Once โ„Ž is found, we can use the homography matrix ๐ป๐ป to perform the mapping
we desire.
Some note for programming:
a. In this task, the homography matrix ๐ป๐ป is calculated using ๐‘‹๐‘‹๐‘ค๐‘ค = ๐ป๐ป๐‘‹๐‘‹๐‘–๐‘– .
b. The information of world coordinates is given in unit of centimeter. Thus, I
assume one pixel is equal to one centimeter.
c. Using four corresponding point pairs, the homography ๐ป๐ป is solved.
d. Similar to what we have done in HW2, at first the four corner points of image
is mapped to the world plane using homography ๐ป๐ป, then the dimension of the
output image is determined using the mapped points. Finally, the points in the
output image are mapped back to the image using ๐ป๐ปโˆ’1 to find the
corresponding pixel values.
2. Remove Projective Distortion โ€“ Vanishing Line
Another way to remove the projective distortion is to use the vanishing lines in
the image. Since an affine homography maps ๐‘™๐‘™โˆž to ๐‘™๐‘™โˆž , all we have to do is to find
a homography that maps the vanishing line back to ๐‘™๐‘™โˆž .
Suppose now we have two line pairs (๐ฟ๐ฟ1 โ€ฒ, ๐ฟ๐ฟ2 โ€ฒ) and (๐‘€๐‘€1โ€ฒ , ๐‘€๐‘€2 โ€ฒ) in the image that
are supposed to be two parallel line pairs in the world plane (๐ฟ๐ฟ1 //๐ฟ๐ฟ2 , ๐‘€๐‘€1 //๐‘€๐‘€2 ) ,
we can find the intersection of this two line pairs, which are called vanishing points:
๐‘ƒ๐‘ƒ1 = ๐ฟ๐ฟ1 โ€ฒ × ๐ฟ๐ฟ2 โ€ฒ
๐‘ƒ๐‘ƒ2 = ๐‘€๐‘€1 โ€ฒ × ๐‘€๐‘€2 โ€ฒ
Then, the vanishing line ๐ฟ๐ฟโ€ฒ is given by:
๐ฟ๐ฟโ€ฒ = ๐‘ƒ๐‘ƒ1 × ๐‘ƒ๐‘ƒ2
Therefore, if the vanishing line ๐ฟ๐ฟโ€ฒ = [๐‘™๐‘™1
the vanishing line back to ๐‘™๐‘™โˆž is given by:
๐‘™๐‘™2
๐‘™๐‘™3 ]T , the homography that maps
1
๐ป๐ป๐‘ƒ๐‘ƒ = ๏ฟฝ 0
๐‘™๐‘™1
0
1
๐‘™๐‘™2
0
0๏ฟฝ
๐‘™๐‘™3
As a result, apply this homography to our image can get rid of the projective
distortion.
Some note for programming:
a. The homography is given by ๐‘‹๐‘‹๐‘ค๐‘ค = ๐ป๐ปp ๐‘‹๐‘‹๐‘–๐‘– . Be careful to the mapping direction.
b. The vanishing line needs to be normalized before putting into ๐ป๐ป๐‘ƒ๐‘ƒ .
c. The homography ๐ป๐ป๐‘ƒ๐‘ƒ can be easily obtained using the vanishing line.
d. Similar to what we have done befroe, at first the four corner points of image
is mapped to the world plane using homography ๐ป๐ป๐‘ƒ๐‘ƒ , then the dimension of
the output image is determined using the mapped points. Finally, the points in
the output image are mapped back to the image using ๐ป๐ป๐‘ƒ๐‘ƒ โˆ’1 to find the
corresponding pixel values.
3. Remove Affine Distortion
When we see the angles are not preserved in the image, there exists the affine
distortion in the image. Suppose now we have two orthogonal lines L =
[๐‘™๐‘™1 ๐‘™๐‘™2 ๐‘™๐‘™3 ]T and M = [๐‘š๐‘š1 ๐‘š๐‘š2 ๐‘š๐‘š3 ]T in the world plane, the angle between this
two lines is given by:
โˆ—
1 0 0
LT Cโˆž
M
โˆ—
cos ฮธ =
, Cโˆž
= ๏ฟฝ0 1 0๏ฟฝ
โˆ— L)(M T C โˆ— M)
๏ฟฝ(LT Cโˆž
โˆž
0 0 0
Suppose now there is a homography ๐ป๐ป applied to the world plane and result in
an image plane, the relation between the transformed lines and the original lines is
given by L = ๐ป๐ป๐‘‡๐‘‡ ๐ฟ๐ฟโ€ฒ , M = ๐ป๐ป๐‘‡๐‘‡ ๐‘€๐‘€โ€ฒ . In addition, the transformed conic is given by
โˆ—โ€ฒ
โˆ—
๐ถ๐ถโˆž
= H๐ถ๐ถโˆž
H . Since cos ฮธ = 0 for two orthogonal lines in the world plane, we have:
โˆ— T โ€ฒ
Lโ€ฒT Ha Cโˆž
Ha M = 0
A 0
๏ฟฝ is the homography that can remove the affine distortion.
0 1
Expand the above equation we get:
Where Ha = ๏ฟฝ
T
[๐‘™๐‘™1 โ€ฒ ๐‘™๐‘™2 โ€ฒ ๐‘™๐‘™3 โ€ฒ] ๏ฟฝAA
0
๐‘ ๐‘ 11
Denote S= AAT =๏ฟฝ๐‘ ๐‘ 
12
๐‘ ๐‘ 12
๐‘ ๐‘ 22 ๏ฟฝ , we have:
๐‘š๐‘š1 โ€ฒ
0๏ฟฝ ๏ฟฝ๐‘š๐‘š โ€ฒ๏ฟฝ = 0
2
0
๐‘š๐‘š3 โ€ฒ
๐‘ ๐‘ 11 ๐‘š๐‘š1 โ€ฒ๐‘™๐‘™1 โ€ฒ + ๐‘ ๐‘ 12 (๐‘™๐‘™1 โ€ฒ๐‘š๐‘š2 โ€ฒ+๐‘™๐‘™2 โ€ฒ๐‘š๐‘š1 โ€ฒ) + ๐‘ ๐‘ 22 ๐‘™๐‘™2 โ€ฒ๐‘š๐‘š2 โ€ฒ = 0
Since we only care about ratios, we can set ๐‘ ๐‘ 22 = 1 . As a result, we would need
two orthogonal line pairs to solve for S. Once we have S, we can take the singular
value decomposition (SVD) on S to get A :
S = AAT = VD2 V T , A = VDV T
Some note for programming:
a. The homography now is given by ๐‘‹๐‘‹๐‘–๐‘– = ๐ป๐ปa ๐‘‹๐‘‹๐‘ค๐‘ค . Be careful to the mapping
direction.
b. When selecting the points to find the homography ๐ป๐ปa , the coordinates of
these points should correspond to the image plane where the projective
distortion is removed.
c. The MATLAB eig function could output negative eigenvalues, we should use
the SVD to get A.
d. To remove the projective distortion and the affine distortion, at first the four
corner points of the original image is mapped to the world plane using
homography ๐ป๐ปa โˆ’1 ๐ป๐ป๐‘ƒ๐‘ƒ , then the dimension of the output image is determined
using the mapped points. Finally, the points in the output image are mapped
back to the image using the inverse of ๐ป๐ปa โˆ’1 ๐ป๐ป๐‘ƒ๐‘ƒ to find the corresponding pixel
values.
e. Poor selection of points could lead to bad results. Select the points carefully.
4. One-Step Method
To remove the projective distortion and the affine distortion at one step, we need
to find a general homography:
A
H=๏ฟฝ T
v
0
๏ฟฝ
1
Since the dual conic in the image plane is given by:
โˆ—โ€ฒ
Cโˆž
=
โˆ— T
HCโˆž
H
T
= ๏ฟฝ AA
v T AT
a
b/2
Av ๏ฟฝ=๏ฟฝb/2
c
vTv
d/2 e/2
d/2
e/2 ๏ฟฝ
f
When there are two lines in the image plane ๐ฟ๐ฟโ€ฒ = [๐‘™๐‘™1 โ€ฒ ๐‘™๐‘™2 โ€ฒ ๐‘™๐‘™3 โ€ฒ] and ๐‘€๐‘€โ€ฒ =
[๐‘š๐‘š1 โ€ฒ ๐‘š๐‘š2 โ€ฒ ๐‘š๐‘š3 โ€ฒ] that is orthogonal to each other in the world plane, we have:
โˆ—โ€ฒ
Lโ€ฒT Cโˆž
a
b/2 d/2
T
c
e/2 ๏ฟฝ [๐‘š๐‘š1 โ€ฒ ๐‘š๐‘š2 โ€ฒ ๐‘š๐‘š3 โ€ฒ]
M = 0 = [๐‘™๐‘™1 โ€ฒ ๐‘™๐‘™2 โ€ฒ ๐‘™๐‘™3 โ€ฒ] ๏ฟฝb/2
d/2 e/2
f
โ€ฒ
Since we only care about the ratios, we set f = 1. Therefore, we need five
orthogonal line pairs to solve for five unknowns. Once the unknowns are solved, we
a
b/2
can again do SVD on S = AAT = ๏ฟฝ
๏ฟฝ to get A matrix, and then solve for
b/2
c
matrix v using v T AT =[d/2 e/2]. By doing this, we get the general homography
that can get rid of the projective distortion and affine distortion.
Some note for programming:
a. The homography now is given by ๐‘‹๐‘‹๐‘–๐‘– = H๐‘‹๐‘‹๐‘ค๐‘ค . Be careful to the mapping
direction.
b. When calculating the orthogonal line pairs, normalize these lines before
solving for H.
a
b/2 d/2
c
e/2 ๏ฟฝ is solved, normalize it before applying
c. When the matrix ๏ฟฝb/2
d/2 e/2
f
singular value decomposition.
d. To remove the projective distortion and the affine distortion, at first the four
corner points of the original image is mapped to the world plane using
homography H โˆ’1 , then the dimension of the output image is determined using
the mapped points. Finally, the points in the output image are mapped back to
the image using H to find the corresponding pixel values.
e. It is possible that the dimension of output image is too large or too small.
Thus, scale the dimension of the output image according to the original image
size before finding the corresponding pixel values.
f. Poor selection of points could lead to bad results. Select the points carefully.
5. Comment
Although the two-steps method seems to be more complicated than the one-step
method, it appears to me that the two-step method is more robust than the one-step
method. First of all, although the two-step method requires more coding lines, it is
more straightforward in concept than the one-step method. Second, when selecting
the points to calculate the homography, the one-step method is very sensitive to the
points being selected, which means it requires longer time to find the correct points
to yield reasonable results. Therefore, I would say the two-steps method is more
practical than the one-step approach when we try to remove the projective and affine
distortion.
6. Results: Two-steps
Image a โ€“ original (green: point to point correspondence; red: parallel lines for vanishing line;
yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.)
Remove projective (point to point correspondence):
Remove affine:
Remove projective (vanishing line):
Remove affine:
Image b - original (green: point to point correspondence; red: parallel lines for vanishing line;
yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.)
Remove projective (point to point correspondence):
Remove affine:
Remove projective (vanishing line):
Remove affine:
Image c - original (green: point to point correspondence; red: parallel lines for vanishing line;
yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.)
Remove projective (point to point correspondence):
Remove affine:
Remove projective (vanishing line):
Remove affine:
7. Results: One-step
Image a - Original (five orthogonal line pairs, red: PQ-PR, PR-RS, RS-SQ, SQ-QP; yellow: PQ-PR)
Remove projective and affine:
Image b โ€“ Original (five orthogonal line pairs, red: PQ-PR, PR-RS, RS-SQ, SQ-QP; yellow: PR-RS)
Remove projective and affine:
Image c โ€“ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP, RP-PQ; yellow: PS-QR)
Remove projective and affine:
8. Results: My Own Images (Two-Steps)
Image a โ€“ Original (red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS
and PS-QR for removing affine.)
Remove projective (vanishing line):
Remove affine:
Image b โ€“ Original (red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS
and PS-QR for removing affine.)
Remove projective (vanishing line):
Remove affine:
9. Results: My Own Images (One-Step)
Image a โ€“ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP; yellow: PQ-QS, PS-QR)
Remove projective and affine:
Image b โ€“ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP; yellow: PQ-QS, PS-QR)
Remove projective and affine: