Cmsc733 Hw01 Sample Solution
-
Upload
hitesh-maidasani -
Category
Documents
-
view
238 -
download
0
Transcript of Cmsc733 Hw01 Sample Solution
-
8/3/2019 Cmsc733 Hw01 Sample Solution
1/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
A s s i g n m e n t 1 o f C M S C 7 3 3
1 . ( C a m e r a m o d e l s ) F o r a c a m e r a , t h e i m a g e x o f a p o i n t X i n s p a c e
i s g i v e n b y : x = PX, w i t h x a n d X h o m o g e n e o u s 3 a n d 4 - v e c t o r s r e s p e c t i v e l y .
( a ) I f P C = 0 , w h e r e C i s a h o m o g e n e o u s 4 - v e c t o r , s h o w t h a t C i s t h e c a m e r a c e n t e r .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
C o n s i d e r t h e p o i n t C a n d a n o t h e r p o i n t A i n 3 D s p a c e , a n y p o i n t o n t h e l i n e p a s s i n g t h r o u g h A a n d
C c a n b e e x p r e s s e d a s ,
X() = A + (1 )C
G i v e a m a p p i n g t h a t m a p s X t o x b y m a t r i x P , x c a n b e r e p r e s e n t e d a s ,
x = P X() = P(A + (1 )C) = P A + (1 )P C
I f P C = 0 , t h e n w e h a v e x = P A
w h i c h m e a n s a l l p o i n t s o n t h e l i n e A C a r e m a p p e d t o t h e s a m e i m a g e p o i n t P A. T h u s t h i s r a y m u s t b e a r a y t h r o u g h t h e c a m e r a c e n t e r , a n d C i s t h e h o m o g e n e o u s r e p r e s e n t a t i o n o f t h e c a m e r a
c e n t e r .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( b ) T h e c a m e r a p r o j e c t i o n m a t r i x P c a n b e w r i t t e n a s : P = KR[I| C], w h e r e K i s t h e c a l i b r a t i o n m a t r i x , R i s t h e r o t a t i o n b e t w e e n t h e c a m e r a a n d w o r l d
c o o r d i n a t e f r a m e s , a n d t h e c a m e r a c e n t e r C i s e x p r e s s e d a s
C = (C, 1). S h o w t h a t t h e c a l i b r a t i o n m a t r i x c a n b e o b t a i n e d f r o m a R Q d e c o m p o s i t i o n o f t h e r s t 3 3s u b m a t r i x o f t h e c a m e r a m a t r i x P .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
O n o n e h a n d , w e k n o w t h a t t h e c a m e r a p r o j e c t i o n m a t r i x P = KR[I| C]. K i s t h e c a l i b r a t i o n m a t r i x , w h i c h i s a l s o a n u p p e r t r i a n g u l a r :
K =
x s x0x y0
1
A n d
Ri s t h e o r t h o g o n a l r o t a t i o n m a t r i x b e t w e e n t h e c a m e r a a n d w o r l d c o o r d i n a t e f r a m e s .
O n t h e o t h e r h a n d , g i v e n a 3 4 c a m e r a p r o j e c t i o n m a t r i x P , t h e n ,
P = [M| MC] = M[I| C]
w h e r e M i s t h e r s t 3 3 s u b m a t r i x o f P , a n d (C, 1) i s t h e c a m e r a c e n t e r . B y R Q d e c o m p o s i t i o n o f M , w e o b t a i n ,
M = AB , w h e r e A i s a n u p p e r t r i a n g u l a r w i t h t h e l a s t e l e m e n t o f t h e l a s t r o w i s 1 , a n d
Bi s o r t h o g o n a l m a t r i x . T h u s ,
P = M[I| C] = KR[I| C]
A s a r e s u l t , w e c a n s e e t h a t t h e t w o m a t r i x A a n d B o f R Q d e c o m p o s i t i o n o f M m a t c h w i t h t h e
c a l i b r a t i o n m a t r i x K a n d r o t a t i o n m a t r i x R r e s p e c t i v e l y . T h u s t h e c a l i b r a t i o n m a t r i x K c a n b e
o b t a i n e d f r o m a R Q d e c o m p o s i t i o n o f t h e r s t 3 3 s u b m a t r i x o f t h e c a m e r a m a t r i x P . = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1
-
8/3/2019 Cmsc733 Hw01 Sample Solution
2/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
( c ) I n s o m e a p p l i c a t i o n w e o b t a i n e d t h e f o l l o w i n g c a m e r a m a t r i x P . F i n d t h e c a m e r a
c e n t e r a n d t h e c a l i b r a t i o n p a r a m e t e r s .
P =
707 679.2 555.4 2898920207 46.6 919.2 6325250
1.4 0.7 1.22 1837
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
G i v e n t h e c a m e r a m a t r i x P a n d t h e e q u a t i o n
P = [M| MC], w e h a v e ,
M =
707 679.2 555.4207 46.6 919.2
1.4 0.7 1.22
MC =
28989206325250
1837
T h e n w e c a n c o m p u t e C b y ,
707 679.2 555.4
207 46.6 919.21.4 0.7 1.22
C =
289892063252501837
B y s o l v i n g t h e l i n e a r e q u a t i o n s , w e g e t ,
C = [4228.776 2362.218 7713.802]T
T h u s t h e c a m e r a c e n t e r C i s ,
C = [4228.776 2362.218 7713.802 1]T
T o c o m p u t e t h e c a l i b r a t i o n m a t r i x , w e a p p l y R Q d e c o m p o s i t i o n t o M , t h e r s t 3 3 s u b m a t r i x o f P ,
M = KR
707 679.2 555.4207 46.6 919.2
1.4 0.7 1.22
=
853.3613 425.0469 302.64780 638.2636 350.0416
0 0 1.0000
0.5529 0.8166 0.16590.4435 0.4569 0.7711
1.4000 0.7000 1.2200
T h u s , t h e c a l i b r a t i o n m a t r i x K i s ,
K =
853.3613 425.0469 302.64780 638.2636 350.0416
0 0 1.0000
F o r t h e d e t a i l s o f c o m p u t a t i o n , p l e a s e c h e c k t h e A p p e n d i x : P r o b 1 c .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2 . ( A n e a n d m e t r i c r e c t i c a t i o n ) C o n s i d e r t h e i m a g e p o s t e d i n t h e
c l a s s w e b p a g e . R e a d t h e i m a g e i n t o m a t l a b a n d u s e m a t l a b t o p e r -
f o r m t h e c a l c u l a t i o n s n e c e s s a r y f o r t h e f o l l o w i n g q u e s t i o n s :
( a ) C a l c u l a t e t w o v a n i s h i n g p o i n t s .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
T h e v a n i s h i n g p o i n t i s t h e i m a g e o f a p o i n t a t i n n i t y . S i n c e p a r a l l e l l i n e s i n t e r s e c t a t i n n i t y , t h e
2
-
8/3/2019 Cmsc733 Hw01 Sample Solution
3/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
F i g u r e 1 : V a n i s h i n g p o i n t s a n d v a n i s h i n g l i n e .
i n t e r s e c t i o n o f p a r a l l e l l i n e s i n t h e i m a g e i s t h e v a n i s h i n g p o i n t . A s a r e s u l t , w e c a n n d t w o p a r a l l e l
l i n e s , a n d n d t h e i n t e r s e c t i o n i n t h e i m a g e , a n d t h e i n t e r s e c t i o n i s o n e v a n i s h i n g p o i n t s . R e p e a t
t h i s p r o c e s s , w e c a n n d a s e c o n d v a n i s h i n g p o i n t .
I n t h e g i v e n i m a g e , f o u r p o i n t s a r e e n o u g h t o d e n e t w o g r o u p s o f p a r a l l e l l i n e s . H o w e v e r , t o m a k e
i t i s e a s i e r t o d i s p l a y , t w o s e t o f p a r a l l e l l i n e s ( e i g h t p o i n t s ) a r e s e l e c t e d , s o w e d o n o t n e e d t o e x t e n d
t h e i m a g e t o o f a r . P l e a s e s e e t h e c o d e i n A p p e n d i x P r o b 2 a b f o r t h e d e t a i l e d c o m p u t a t i o n . H e r e i s
j u s t t h e t w o v a n i s h i n g p o i n t s i n t h e i m a g e ( F i g u r e 1 ) .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( b ) F i n d t h e i m a g e o f t h e l i n e a t i n n i t y .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
F o l l o w i n g 2 ( a ) , t h e i m a g e o f t h e l i n e a t i n n i t y s h o u l d p a s s t h r o u g h t h e t w o v a n i s h i n g p o i n t s ,
o b t a i n e d i n 2 ( a ) . A s a r e s u l t , t h e l i n e t h a t c o n n e c t s t h e t w o v a n i s h i n g p o i n t s a r e t h e v a n i s h i n g l i n e .
S e e F i g u r e 1 . T h e d e t a i l s o f c o m p u t a t i o n a r e i n A p p e n d i x P r o b 2 a b .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( c ) C a l c u l a t e a h o m o g r a p h y t h a t m a p s t h e l i n e a t i n n i t y t o i t s c a n o n i c a l p o s i t i o n .
T h i s h o m o g r a p h y p r o d u c e s a n a n e r e c t i c a t i o n . A p p l y t h i s h o m o g r a p h y t o t h e
i m a g e .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
I n p r o b 2 ( c ) ( e ) , w e w i l l u s e a s m a l l p a r t o f t h e w h o l e i m a g e , s h o w n i n F i g u r e 2 .
U s i n g t h e s a m e w a y i n t r o d u c e d i n 2 ( a ) a n d 2 ( b ) , w e c o m p u t e t h e v a n i s h i n g l i n e o f t h i s s m a l l i m a g e
a s l = (l1, l2, l3)T = (0.0005, 0.0035, 18), w h i l e t h e l i n e a t i n n i t y i s l = (0, 0, 1)
T. S o t h e
3
-
8/3/2019 Cmsc733 Hw01 Sample Solution
4/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
F i g u r e 2 : A s m a l l p a r t o f t h e w h o l e i m a g e
F i g u r e 3 : A n e r e c t i e d i m a g e
h o m o g r a p h y t o m a p l t o l s a t i s e s :
H = HA
1 0 00 1 0
l1 l2 l3
w h e r e
HA i s a n y a n e t r a n s f o r m a t i o n . H e r e , w e s u p p o s e HA i s t h e i d e n t i t y m a t r i x . T h u s , t h e t r a n s f o r m a t i o n m a t r i x i s ,
H = 1 0 00 1 0
0.0005 0.0035 1
A p p l y t h i s h o m o g r a p h y t o t h i s s m a l l i m a g e , w e g e t F i g u r e 3 .
T h e c o r r e s p o n d i n g c o d e i s i n A p p e n d i x p r o b 2 c d e .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = `
( d ) C a l c u l a t e t h e d u a l c o n i c ( t h e i m a g e o f t h e d u a l c o n i c ) .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
S u p p o s e
la n d
ma r e t h e t w o l i n e s i n t h e a n e l y r e c t i e d i m a g e c o r r e s p o n d t o t h e t w o o r t h o g o n a l
l i n e s i n t h e w o r l d p l a n e . T h e n , t h e i m a g e o f t h e d u a l c o n i c
C
,
la n d
ms h o u l d s a t i s f y ,
lT
C
m
= 0
w h e r e , C
=
KKT 0
0 0
. A n d KKT i s a c t u a l l y s y m m e t r i c w i t h t h r e e i n d e p e n d e n t e l e m e n t s .
S i n c e w e h a v e a l r e a d y h a v e t h e a n e l y r e c t i e d i m a g e f r o m 2 ( c ) , w e c a n c h o o s e t w o p a i r s o f l i n e s
c o r r e s p o n d i n g t o t h e o r t h o g o n a l l i n e s i n t h e w o r l d p l a n e , a n d u s e t h e a b o v e e q u a t i o n t o c o m p u t e
C
. T h e d e t a i l s o f c o m p u t a t i o n i s i n A p p e n d i x P r o b 2 c d e , a n d t h e o b t a i n e d i m a g e o f t h e d u a l c o n i c
i s ,
C
=
2.568 0.359 0 0.359 1 0 0 0 0
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
4
-
8/3/2019 Cmsc733 Hw01 Sample Solution
5/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
F i g u r e 4 : M e t r i c r e c t i e d i m a g e
( e ) U s e i t t o p r o d u c e a m e t r i c r e c t i c a t i o n o f t h e i m a g e .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
O n c e w e h a v e C
, w e c a n r e c o v e r K f r o m C
b y e i g e n v e c t o r d e c o m p o s i t i o n . T h e o b t a i n e d m a t r i x
K i s ,
K =
0.2046 1.58930.9380 0.3467
A s a r e s u l t , t h e a n e t r a n s f o r m a t i o n m a t r i x Ha i s ,
Ha =
0.2046 1.5893 00.9380 0.3467 0
0 0 1
A p p l y
Hat o t h i s i m a g e , w e g e t F i g u r e 4 . P l e a s e c h e c k A p p e n d i x P r o b 2 c d e f o r d e t a i l s o f c o m p u t a t i o n .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
3 . ( P l a n a r m o s a i c s ) C o n s i d e r t h e i m a g e s p o s t e d i n t h e c l a s s w e b s i t e .
T h e y a r e i m a g e s o f a s c e n e t a k e n b y a c a m e r a o n l y r o t a t i n g a r o u n d
a n a x i s p a s s i n g t h r o u g h i t s c e n t e r . T h u s a n y t w o o f t h e i m a g e s a r e
s e p a r a t e d b y a r o t a t i o n . C o n s i d e r a p o i n t X i n s p a c e a n d i t s i m a g e s
x a n d x ' i n t w o o f t h e i m a g e s . T h e n , a s s u m i n g t h a t t h e r s t c a m e r a
c o o r d i n a t e s y s t e m c o i n c i d e s w i t h t h e w o r l d c o o r d i n a t e s y s t e m , w e
h a v e : x = K[I|O]X, x = K[R|O]X = KRK1x. T h u s , x = Hx, w i t h H= KRK1 . H i s c a l l e d a c o n j u g a t e r o t a t i o n .
5
-
8/3/2019 Cmsc733 Hw01 Sample Solution
6/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
( a ) S h o w t h a t H a n d R h a v e t h e s a m e e i g e n v a l u e s u p t o s c a l e ( o n e r e a l a n d t w o
c o m p l e x ) .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
G i v e n H = KRK1 , t h e e i g e n v a l u e s a n d e i g e n v e c t o r s v o f H s a t i s f y :
Hv = v
KRK1v = v
RK1v = K1v = K1v
Rv = v, where v = K1v
A s a r e s u l t , w e c a n s e e t h a t i s a l s o t h e e i g e n v a l u e s o f R , w h i l e v i s t h e e i g e n v e c t o r s o f R . T h u s H a n d R h a v e t h e s a m e e i g e n v a l u e s u p t o s c a l e .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( b ) S h o w t h a t t h e e i g e n v e c t o r c o r r e s p o n d i n g t o t h e r e a l e i g e n v a l u e i s t h e v a n i s h i n g
p o i n t o f t h e r o t a t i o n a x i s .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
T h e r o t a t i o n o f a v e c t o r v c a n b e r e p r e s e n t e d b y
v = Rv
w h e r e R i s t h e r o t a t i o n m a t r i x . I f v i s t h e d i r e c t i o n o f t h e r o t a t i o n a x i s , v s h o u l d b e t h e s a m e a s vu p t o s c a l e . T h u s w e h a v e ,
v = v = Rv
W h e r e i s s c a l i n g p a r a m e t e r , t h u s i t i s a r e a l n u m b e r . A l s o , f r o m t h e a b o v e e q u a t i o n , w e s e e t h a t a c t u a l l y v i s e i g e n v e c t o r c o r r e s p o n d i n g t o t h e r e a l e i g e n v a l u e o f R .
S i n c e t h e v a n i s h i n g p o i n t o f t h e r o t a t i o n a x i s i s d e n e d a s t h e d i r e c t i o n o f t h e r o t a t i o n a x i s , w e c a n
s a y t h a t t h e e i g e n v e c t o r c o r r e s p o n d i n g t o t h e r e a l e i g e n v a l u e i s t h e v a n i s h i n g p o i n t o f t h e r o t a t i o n
a x i s .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( c ) S h o w t h a t H i s t h e i n n i t e h o m o g r a p h y ( i . e . t h e h o m o g r a p h y i n d u c e d b y t h e
p l a n e a t i n n i t y ) .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
I n t h i s p r o b l e m , t w o c a m e r a m a t r i x a r e p r o v i d e d . L e t ' s d e n o t e i t a s ,
P1 = K[I|0] P2 = K[R|0]
S u p p o s e t h e w o r l d p l a n e i s E = (nT, d)T , w h e r e d i s t h e o r t h o g o n a l d i s t a n c e f r o m t h e r s t p o s i t i o n
o f t h e c a m e r a t o t h e w o r l d p l a n e . T h u s t h e p o i n t s o n t h i s p l a n e s h o u l d s a t i s f y : nTX+ d = 0. A s a r e s u l t , t h e h o m o g r a p h y i n d u c e d b y t h i s p l a n e c a n b e r e p r e s e n t e d a s ,
H = K(R 0 nT/d)K1 = KRK1 = limd
K(R t nT/d)K1
A s a r e s u l t , w e c a n t h i n k H a s a h o m o g r a p h y i n d u c e d b y a w o r l d p l a n e a t i n n i t y . T h u s , w e c a l l H
i s t h e i n n i t e h o m o g r a p h y .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
6
-
8/3/2019 Cmsc733 Hw01 Sample Solution
7/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
F i g u r e 5 : A m o s a i c i m a g e o f t h e 7 g i v e n i m a g e s .
( d ) U s e t h e i m a g e s p r o v i d e d t o p r o d u c e a p l a n a r p a n o r a m i c m o s a i c .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
G i v e n t w o i m a g e s , t h e b a s i c i d e a f o r m a p p i n g t h e m i s : d e n e o n e o f t h e m a s t h e b a s e i m a g e , t h e
o t h e r o n e a s n e w i m a g e . T h e n , n d t w o c o r r e s p o n d i n g p o i n t s o n e a c h i m a g e a n d c a l c u l a t e t h e t r a n s -
f o r m a t i o n m a t r i x . F i n a l l y , w a r p t h e n e w i m a g e t o t h e b a s e i m a g e a c c o r d i n g t o t h e t r a n s f o r m a t i o n
m a t r i x . O n e t h i n g t o n o t i c e i s t h a t t h e c o o r d i n a t e s o f i m a g e p o i n t s s h o u l d c h a n g e w h i l e w a r p i n g ,
t h u s w e n e e d t o c o m p u t e t h a t o s e t .
S i m i l a r l y , g i v e n a s e q u e n c e o f i m a g e s , w e c a n a l w a y s d e n e t h e r s t o n e a s t h e b a s e i m a g e , a
s e c o n d o n e a s t h e n e w i m a g e . A f t e r t h e r s t w a r p i n g , u s e t h e r e s u l t a s t h e u p d a t e d b a s e i m a g e , a n d
m a p w i t h t h e n e x t o n e . R e p e a t t h i s p r o c e s s t i l l a l l t h e i m a g e s a r e m a p p e d t o t h e b a s e i m a g e , w h i c h
i s n a l l y t h e r e q u i r e d p l a n a r p a n o r a m i c m o s a i c .
T h e d e t a i l s c a n b e f o u n d i n A p p e n d i x P r o b 3 d . T h e m o s a i c i m a g e i s s h o w n i n 5 .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
4 . ( P r o j e c t i v e r e c o n s t r u c t i o n u s i n g c o p l a n a r p o i n t s ) . A s s u m e t w o s e t s o f
f o u r k n o w n c o p l a n a r p o i n t s i n t h e s c e n e A , B , C , D a n d E , F , G , H g i v i n g
i m a g e s a , b , c , d a n d e , f , g , h f o r a n n o n c a l i b r a t e d c a m e r a w i t h c a m e r a
c e n t e r O . C o n s i d e r a n u n k n o w n p o i n t M i n t h e s c e n e p r o d u c i n g a n
i m a g e m .
( a ) S h o w h o w t o d e t e r m i n e t h e v i e w i n g r a y O m .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
G i v e n v e c o p l a n a r p o i n t s O , A , B , C , D , w e c a n t h i n k i t a s f o u r l i n e s O A , O B , O C a n d O D c r o s s
a t p o i n t O , t h u s t h e c r o s s r a t i o i s d e n e d a s ,
CRO(A,B,C,D) =sin(OA,OC)sin(OB,OD)
sin(OA,OD)sin(OB,OC)
7
-
8/3/2019 Cmsc733 Hw01 Sample Solution
8/17
A s s i g n m e n t 1 o f C M S C 7 3 3 B y
I n p r o j e c t i v e t r a n s f o r m a t i o n , t h e c r o s s r a t i o i s i n v a r i a n t . W e w i l l u s e t h e n o t a t i o n CRO(A,B,C,D)t o d e n o t e t h e c r o s s r a t i o o f f o u r p o i n t s A , B , C , D a t p o i n t O .
I n t h i s p r o b l e m , s u p p o s e t h e p o i n t M i s p r o j e c t e d t o M1 i n t h e p l a n e o f A , B , C , D , t h e n w e c a n c o m p u t e
M1b y t h e i n v a r i a n t c r o s s r a t i o .
CRa(b,c,d,m) = CRA(B, C, D, M1)
CRb(a,c,d,m) = CRB(A,C,D,M1)
CRc(a,b,d,m) = CRC(A , B, D, M1)
S i n c e A , B , C , D a n d a , b , c , d a n d m a r e g i v e n , w e c a n g e t t h e s p e c i c c o o r d i n a t e s o f M1 .
I n t h e s a m e w a y , w e c a n c o m p u t e M2 , t h e p r o j e c t i o n o f p o i n t M t o t h e p l a n e o f E , F , G , H , b y
CRe(f, g, h, m) = CRE(F,G,H,M2)
CRf(e,g,h,m) = CRF(E, G, H , M2)
CRg(e,f,h,m) = CRG(E, F , H , M2)
A s a r e s u l t , t h e v i e w i n g r a y O m c a n b e d e t e r m i n e d b y
M1 a n d M2 .= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( b ) U s e ( a ) t o d e v e l o p a m e t h o d f o r n d i n g t h e c a m e r a c e n t e r .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
S i m i l a r l y , c o n s i d e r t h e p r o j e c t i o n A ' o f A t o t h e p l a n e o f E , F , G , H , w e c a n o b t a i n A ' b y ,
CRe(f, g, h, a) = CRE(F,G,H,A)
CRf(e,g,h,a) = CRF(E, G, H , A)
CRg(e,f,h,a) = CRG(E, F , H , A)
B y n o w , w e h a v e A , A ' ,
M1 a n d M2 , a n d w e h a v e t w o r a y s AA
a n d
M1M2 f r o m t h e c a m e r a c e n t e r . T h u s t h e c a m e r a c e n t e r O c a n b e d e t e r m i n e d b y t h e i n t e r s e c t i o n o f t h e r a y
AAa n d t h e r a y
M1M2 .= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
( c ) R e p e a t ( a ) a n d ( b ) f o r t h e c a s e w h e r e w e a r e g i v e n 6 p o i n t s i n s p a c e a n d t h e i r
i m a g e s ( i n s t e a d o f t w o s e t s o f f o u r c o p l a n a r p o i n t s ) .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
G i v e n t h e c a m e r a c e n t e r O , s i x p o i n t s A , B , C , D , E , F a n d t h e i r i m a g e s , w e h a v e s i x p l a n e s n a m e l y
O A B , O A C , O A D , O A E , O A F , w h i c h i n t e r s e c t a n i m a g e p l a n e a t IAIB , IAIC, IAID , IAIE , IAIF .T a k e a n o t h e r p l a n e i n t o s c e n e , O A i n t e r s e c t s t h e p l a n e a t
IA , a n d A B , A C , A D , A E , A F i n t e r s e c t w i t h t h i s p l a n e a t
IB,
IC,
ID,
IE,
IFr e s p e c t i v e l y .
T h e n w e c a n m e a s u r e t h e c r o s s r a t i o u s i n g t h e i n t e r s e c t i o n s IAIB , IAIC, . . . , IAIF w i t h t h e i m - a g e p l a n e , t h u s w e k n o w c r o s s r a t i o o f IAIB , IAIC , IAID , IAIE . S i m i l a r l y , w e c a n g e t t h e c r o s s r a t i o o f IAIB , IAIC , IAID , IAIF . A s a r e s u l t , IA l i e s o n t h e i n t e r s e c t i o n o f t h e t w o c o n - i c s . A s l o n g a s w e n d IA , w e h a v e t w o p o i n t s A a n d IA o n t h e r a y p a s s i n g f r o m t h e c a m e r a c e n t e r O .
I n t h e s i m i l a r w a y , w e c a n n d t w o p o i n t s o n a n o t h e r r a y p a s s i n g f r o m t h e c a m e r a c e n t e r O . A s a
r e s u l t , t h e i n t e r s e c t i o n o f t h e t w o r a y s g i v e s u p t h e c a m e r a c e n t e r O .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
8
-
8/3/2019 Cmsc733 Hw01 Sample Solution
9/17
Appendix: Prob1c
% Original dataP = [707 679.2 555.4 -2898920;
207 46.6 919.2 -6325250;1.4 -0.7 1.22 -1837];
M = P(:, 1:3);
% Compute the camera centerC = sym('[c1; c2; c3]');f = M*C + P(:,4);res = solve(f);
C_hat = ones(3, 1);names = fieldnames(res);for j = 1 : numel(names)
C_hat(j) = res.(names{j});end
% Compute the calibration matrix K by RQ decompositionReverseRows = [0 0 1; 0 1 0 ; 1 0 0];[Q R] = qr((ReverseRows * M)');K = ReverseRows * R' * ReverseRows;R = ReverseRows * Q';scale = K(3,3);K(:,3) = K(:, 3) ./ scale;R(3,:) = R(3, :) .* scale;
-
8/3/2019 Cmsc733 Hw01 Sample Solution
10/17
Appendix: Prob2ab
clear;close all;
%% Get the image.image = imread('hw1_q2_vpoint-data.jpg');image = rgb2gray(image);img_sz = size(image);
figure, imshow(image);
%% One vanishing point[x, y] = ginput2(2);pA1 = [x y];pA1_ext = [x y [1;1]];
[x, y] = ginput2(2);pA2 = [x y];pA2_ext = [x y [1;1]];
lA1 = cross(pA1_ext(1,:), pA1_ext(2,:));lA2 = cross(pA2_ext(1,:), pA2_ext(2,:));vA = cross(lA1, lA2);pA = vA ./ vA(3);pA = pA(1:2);
%% Another vanishing point[x, y] = ginput2(2);pB1 = [x, y];pB1_ext = [x y [1;1]];
[x, y] = ginput2(2);pB2 = [x y];pB2_ext = [x y [1;1]];
lB1 = cross(pB1_ext(1,:), pB1_ext(2,:));lB2 = cross(pB2_ext(1,:), pB2_ext(2,:));vB = cross(lB1, lB2);pB = vB ./ vB(3);pB = pB(1:2);
%% Vanishing linevAB = cross(vA, vB);vAB = vAB ./ vAB(3);
%% Extend the image
pA = floor(pA);pB = floor(pB);
LEFT = 0; RIGHT = 0; UP = 0; DOWN = 0;MARGIN = 0;img_sz_new = img_sz;
-
8/3/2019 Cmsc733 Hw01 Sample Solution
11/17
if pA(1) < 1
LEFT = LEFT + (1 - pA(1));elseif pA(1) > img_sz_new(2)
RIGHT = RIGHT + (pA(1) - img_sz_new(2));end
if pA(2) < 1UP = UP + (1 - pA(2));
elseif pA(2) > img_sz_new(1)DOWN = DOWN + (pA(2) - img_sz_new(1));
end
img_sz_new(2) = img_sz(2) + LEFT + RIGHT ;img_sz_new(1) = img_sz(1) + UP + DOWN;
if pB(1) < 1LEFT = LEFT + (1 - pB(1));
elseif pB(1) > img_sz_new(2)RIGHT = RIGHT + (pB(1) - img_sz_new(2));end
if pB(2) < 1UP = UP + (1 - pB(2)) + 10;
elseif pB(2) > img_sz_new(1)DOWN = DOWN + (pB(2) - img_sz_new(1));
end
% extendUP = UP + MARGIN;if LEFT > 0
LEFT = LEFT + MARGIN;endif RIGHT > 0
RIGHT = RIGHT + MARGIN;endimg_sz_new(2) = img_sz(2) + LEFT + RIGHT;img_sz_new(1) = img_sz(1) + UP + DOWN;
img_ext = ones(img_sz_new) + 255;img_ext(1+UP : img_sz(1)+UP , 1 + LEFT : img_sz(2) + LEFT) = image;figure, imshow(uint8(img_ext));hold on;
%% plot the vanishing line
Aline1 = [pA1; pA];Aline2 = [pA2; pA];plot(Aline1(:, 1) + LEFT, Aline1(:, 2) + UP, 'g--o');plot(Aline2(:, 1) + LEFT, Aline2(:, 2) + UP, 'g--o');hold on;
plot(pA(1) + LEFT, pA(2) + UP, 'g*');hold on;
-
8/3/2019 Cmsc733 Hw01 Sample Solution
12/17
Bline1 = [pB1; pB];Bline2 = [pB2; pB];plot(Bline1(:, 1) + LEFT, Bline1(:, 2) + UP, 'b--o');plot(Bline2(:, 1) + LEFT, Bline2(:, 2) + UP, 'b--o');hold on;
plot(pB(1) + LEFT, pB(2) + UP, 'b*');hold on;
vline = [pA; pB];plot(vline(:,1)+LEFT, vline(:,2) + UP, 'r-');
-
8/3/2019 Cmsc733 Hw01 Sample Solution
13/17
Appendix: Prob2cde
clc;close all;clear;
%% Get a small part of the whole imageimage = imread('hw1_q2_vpoint-data.jpg');image = rgb2gray(image);
image = image(240:320, 200:500);figure, imshow(image);
imwrite(image, 'prob2c_origin.png')
%% Compute the vanishing line
% One vanishing point[x, y] = ginput2(2);
pA1 = [x y [1;1]];
[x, y] = ginput2(2);pA2 = [x y [1;1]];
lA1 = cross(pA1(1,:), pA1(2,:));lA2 = cross(pA2(1,:), pA2(2,:));vA = cross(lA1, lA2);
% Another vanishing point[x, y] = ginput2(2);pB1 = [x y [1;1]];
[x, y] = ginput2(2);pB2 = [x y [1;1]];
lB1 = cross(pB1(1,:), pB1(2,:));lB2 = cross(pB2(1,:), pB2(2,:));vB = cross(lB1, lB2);
% Vanishing linevAB = cross(vA, vB);vAB = vAB ./ vAB(3);
%% Obtain the projective transformation matrix based on the vanishing
line
RE = eye(3);RE(3,:) = vAB;
HA = [1 0 0; 0 1 0; 0 0 1];H = HA * RE;
% Projective transformation
-
8/3/2019 Cmsc733 Hw01 Sample Solution
14/17
tform = maketform('projective',H');img2 = imtransform(image, tform, 'Size', size(image));
imwrite(img2, 'prob2c.png')figure, imshow(img2), hold on;
%% Obtain the image of the dual conic
% Choose one pair of orthogonal lines: line by line, two points on eachline
[x, y] = ginput2(2);pA1 = [x y];plot(pA1(:,1), pA1(:,2), 'bx'), hold on;
[x, y] = ginput2(2);pA2 = [x y];plot(pA2(:,1), pA2(:,2), 'bo'), hold on;
co = sym('[k; -1; b]');pA1_ex = [pA1 ones(2,1)];f = pA1_ex * co;result = solve(f);coA1 = [result.k, -1, result.b];
pA2_ex = [pA2 ones(2, 1)];f = pA2_ex * co;result = solve(f);coA2 = [result.k, -1, result.b];
% Choose another pair of orthogonal lines: line by line, two points on
each line
[x, y] = ginput2(2);pB1 = [x y];plot(pB1(:,1), pB1(:,2), 'go'), hold on;
[x, y] = ginput2(2);pB2 = [x y];plot(pB2(:,1), pB2(:,2), 'gx'), hold on;
co = sym('[k; -1; b]');pB1_ex = [pB1 ones(2,1)];f = pB1_ex * co;result = solve(f);coB1 = [result.k, -1, result.b];
pB2_ex = [pB2 ones(2, 1)];f = pB2_ex * co;result = solve(f);coB2 = [result.k, -1, result.b];
% Compute the image of dual conic
-
8/3/2019 Cmsc733 Hw01 Sample Solution
15/17
dc = sym('[a b 0; b 1 0; 0 0 0]');f = [coA1 * dc * coA2'; coB1 * dc * coB2'];result = solve(f);dualconic = [result.a result.b 0; result.b 1 0; 0 0 0];dualconic = double(dualconic);
%% Matric Rectification% Recover K from the image of dual conicS = dualconic(1:2, 1:2);[vec, val] = eig(S);K = vec * (val^0.5);
% Get the affine transformation matrixHa = zeros(3,3);Ha(1:2, 1:2) = K;% Ha = dualconic;Ha(3, 3) = 1;
% Affine transformationtform = maketform('affine',inv(Ha'));img3 = imtransform(img2, tform);figure, imshow(img3);
imwrite(img3, 'prob2e.png')
-
8/3/2019 Cmsc733 Hw01 Sample Solution
16/17
Appendix: Prob3
img_base = double(imread('mosaic-data/mosaic-00000000.jpg')) / 255;
for index = 1 : 1 : 6path = strcat('mosaic-data/mosaic-0000000', int2str(index), '.jpg');img = double(imread(path)) / 255;
% obtain size[h_base, w_base, d_base] = size(img_base);[h, w, d] = size(img);
close all;
% get two sets of corresponding points from user:% two points per imagefigure; subplot(1,2,1); image(img_base); axis image; hold on;title('base image');[x_base, y_base] = ginput2(2);subplot(1,2,2); image(img); axis image; hold on;title('new image');[x, y] = ginput2(2);
% estimate the parametersparam = [x' y'; y' -x'; 1 1 0 0; 0 0 1 1]';base = [x_base; y_base];t = param \ base; % solve the linear system
% get the transformation matrix HH = [t(1) t(2) t(3); -t(2) t(1) t(4); 0 0 1];
% warp corners of the new image to determine the size of the outputimage
corner_warp = H*[ 1 1 w w; 1 h 1 h; 1 1 1 1];x_wp = min( [ corner_warp(1,:) 0 ] ) : max( [corner_warp(1,:)
w_base] ); % min x : max xy_wp = min( [ corner_warp(2,:) 0 ] ) : max( [corner_warp(2,:)
h_base] ); % min y : max y[x_w,y_w] = ndgrid(x_wp,y_wp);[w_w, h_w] = size(x_w);
% backwards transformbt = H \ [ x_w(:) y_w(:) ones(w_w * h_w,1) ]'; % warp
% re-sample pixel valuesclear img_temp;bt1_rs = reshape( bt(1,:), w_w, h_w)';bt2_rs = reshape( bt(2,:), w_w, h_w)';img_temp(:,:,1) = interp2(img(:,:,1), bt1_rs, bt2_rs, 'nearest');img_temp(:,:,2) = interp2(img(:,:,2), bt1_rs, bt2_rs, 'nearest');img_temp(:,:,3) = interp2(img(:,:,3), bt1_rs, bt2_rs, 'nearest');
% get offset
-
8/3/2019 Cmsc733 Hw01 Sample Solution
17/17
offset = -round( [ min( [ corner_warp(1,:) 0 ] )min( [ corner_warp(2,:) 0 ] ) ] );
% copy base image into the warped imagefor ii = 1 : h_base
for jj = 1 : w_base
if img_base(ii,jj) > 0img_temp(ii+offset(2),jj+offset(1), :) =img_base(ii,jj,:);
endend
end
img_base = img_temp;end
% show the resultfigure; image(img_base); axis image;title('mosaic image');
imwrite(uint8(img_base*255), 'result.png');