CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... ·...

48
CS559: Computer Graphics Lecture 8: Warping, Morphing, 3D Transforma?on Li Zhang Spring 2010 Most slides borrowed from Yungyu Chuang

Transcript of CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... ·...

Page 1: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

CS559:  Computer  Graphics  

Lecture  8:  Warping,  Morphing,  3D  Transforma?on  

Li  Zhang  Spring  2010  

Most  slides  borrowed  from  Yungyu  Chuang  

Page 2: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Last  ?me:  Forward  warping  fwarp(I, I’, T) { for (y=0; y<I.height; y++) for (x=0; x<I.width; x++) { (x’,y’)=T(x,y); I’(x’,y’)=I(x,y); } } I I’

x

x’

T

Page 3: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Last  ?me:  Inverse  warping  iwarp(I, I’, T) { for (y=0; y<I’.height; y++) for (x=0; x<I’.width; x++) { (x,y)=T-1(x’,y’); I’(x’,y’)=I(x,y); } } I I’

x x’

T-1

Page 4: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Non-­‐parametric  image  warping  

•  Mappings  implied  by  correspondences  

•  Inverse  warping  

P’ ?

Page 5: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Non-­‐parametric  image  warping  

Page 6: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Warping  between  two  triangles  

•  Idea:  find  an  affine  that  transforms  ABC  to  A’B’C’    

A  

C  B  

A’  

C’  

B’  

Page 7: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Barycentric  coordinates  

•  Idea:  represent  P  using  A1,A2,A3  

Page 8: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Non-­‐parametric  image  warping  

P’

Barycentric coordinate

P

Turns  out  to  be  equivalent  to  affine  transform,  why?    

Page 9: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Non-­‐parametric  image  warping  

Gaussian

View this problem as a signal reconstruction problem

Page 10: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Demo  

•  hWp://www.colonize.com/warp/warp04-­‐2.php  

•  Warping  is  a  useful  opera?on  for  mosaics,  video  matching,  view  interpola?on  and  so  on.  

Page 11: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  

Page 12: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  •  The  goal  is  to  synthesize  a  fluid  transforma?on  from  one  image  to  another.  

image #1 image #2 dissolving

•  Cross dissolving is a common transition between cuts, but it is not good for morphing because of the ghosting effects.

(1-t) · Image1 + t · Image2

Page 13: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  •  Why  ghos?ng?  

•  Morphing  =  warping  +  cross-­‐dissolving  

shape (geometric)

color (photometric)

Page 14: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

morphing

cross-dissolving

Image  morphing  image #1 image #2

warp warp

Page 15: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Morphing  sequence  

Page 16: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  

create  a  morphing  sequence:  for  each  ?me  t  1.  Create  an  intermediate  warping  field  (by  

interpola?on)  

t=0 t=1 t=0.33

A(0) A(1) A(0.33)

B(0) B(1) B(0.33) C(0) C(1) C(0.33)

Page 17: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  

create  a  morphing  sequence:  for  each  ?me  t  1.  Create  an  intermediate  warping  field  (by  

interpola?on)  2.  Warp  both  images  towards  it  

t=0 t=1 t=0.33

A(0) A(1) A(0.33)

B(0) B(1) B(0.33) C(0) C(1) C(0.33)

Page 18: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  

create  a  morphing  sequence:  for  each  ?me  t  1.  Create  an  intermediate  warping  field  (by  

interpola?on)  2.  Warp  both  images  towards  it  

t=0 t=1 t=0.33

A(0) A(1) A(0.33)

B(0) B(1) B(0.33) C(0) C(1) C(0.33)

Page 19: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Image  morphing  

create  a  morphing  sequence:  for  each  ?me  t  1.  Create  an  intermediate  warping  field  (by  

interpola?on)  2.  Warp  both  images  towards  it  

3.  Cross-­‐dissolve  the  colors  in  the  newly  warped  images  

t=0 t=1 t=0.33

A(0) A(1) A(0.33)

B(0) B(1) B(0.33) C(0) C(1) C(0.33)

Page 20: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

More  complex  morph  

•  Triangular  Mesh  

Page 21: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Results  

Michael Jackson’s MTV “Black or White” http://www.youtube.com/watch?v=YVoJ6OO6lR4 (5:20 later)

Page 22: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Mul?-­‐source  morphing  

Page 23: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Mul?-­‐source  morphing  

Page 24: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

The  average  face  

•  hWp://www.uni-­‐regensburg.de/Fakultaeten/phil_Fak_II/Psychologie/Psy_II/beautycheck/english/index.htm  

Page 25: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

3D  Face  morphing  

http://www.youtube.com/watch?v=nice6NYb_WA Blanz and Vetter, SIGGRAPH 1998

Page 26: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Where  to  now…  

•  We  are  now  done  with  images  

Page 27: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

 3D  Graphics  Pipeline  

Rendering (Creating, shading images from geometry, lighting, materials)

Modeling (Creating 3D Geometry)

Page 28: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

3D  Graphics  Pipeline  

Rendering (Creating, shading images from geometry, lighting, materials)

Modeling (Creating 3D Geometry)

Want to place it at correct location in the world Want to view it from different angles Want to scale it to make it bigger or smaller Need transformation between coordinate systems -- Represent transformations using matrices and matrix-vector multiplications.

Page 29: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Next  …  

•  We  will  spend  several  weeks  on  the  mechanics  of  3D  graphics  – 3D  Transform  

– Coordinate  systems  and  Viewing  

– Drawing  lines  and  polygons  –  Ligh?ng  and  shading  

•  More  advanced:  mathema?cal  representa?on  of  lines  and  surfaces,  texture  mapping,  anima?on  

Page 30: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Recall:  All  2D  Linear  Transforma?ons  •  Linear  transforma?ons  are  combina?ons  of  …  

–  Scale,  – Rota?on,  –  Shear,  and  – Mirror  

Page 31: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

2D  Rota?on  

•  Rotate  counter-­‐clockwise  about  the  origin  by  an  angle  θ  

x

y

x

y

θ

Page 32: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Rota?ng  About  An  Arbitrary  Point  

•  What  happens  when  you  apply  a  rota?on  transforma?on  to  an  object  that  is  not  at  the  origin?  

x

y

?

Page 33: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Rota?ng  About  An  Arbitrary  Point  

•  What  happens  when  you  apply  a  rota?on  transforma?on  to  an  object  that  is  not  at  the  origin?  –  It  translates  as  well  

x

y

x

Page 34: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

How  Do  We  Fix  it?  

•  How  do  we  rotate  an  about  an  arbitrary  point?  – Hint:  we  know  how  to  rotate  about  the  origin  of  a  coordinate  system  

Page 35: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Rotating About An Arbitrary Point

x

y

x

y

x

y

x

y

Page 36: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Back  to  Rota?on  About  a  Pt  

•  Say  R  is  the  rota?on  matrix  to  apply,  and  p  is  the  point  about  which  to  rotate  

•  Transla?on  to  Origin:  •  Rota?on:  •  Translate  back:  •  How  to  express  all  the  transforma?on  using  matrix  mul?plica?on?    

Page 37: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Scaling  an  Object  not  at  the  Origin  

•  What  happens  if  you  apply  the  scaling  transforma?on  to  an  object  not  at  the  origin?  

Page 38: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Composing  rota?ons,  scales  

Rotation and scaling are not commutative.

Page 39: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Inver?ng  Composite  Transforms  

•  Say  I  want  to  invert  a  combina?on  of  3  transforms  

•  Op?on  1:  Find  composite  matrix,  invert  

•  Op?on  2:  Invert  each  transform  and  swap  order  

Page 40: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Inver?ng  Composite  Transforms  

•  Say  I  want  to  invert  a  combina?on  of  3  transforms  

•  Op?on  1:  Find  composite  matrix,  invert  

•  Op?on  2:  Invert  each  transform  and  swap  order  

•  Obvious  from  proper?es  of  matrices  

Page 41: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Homogeneous  Transform  Advantages  

•  Unified  view  of  transforma?on  as  matrix  mul?plica?on  – Easier  in  hardware  and  solware  

•  To  compose  transforma?ons,  simply  mul?ply  matrices  – Order  maWers:  BA  vs  AB  

•  Allows  for  transforming  direc?onal  vectors  

•  Allows  for  non-­‐affine  transforma?ons  when  last  row  is  not  (0,0,1)  

Page 42: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Direc?ons  vs.  Points  

•  We  have  been  talking  about  transforming  points  

•  Direc?ons  are  also  important  in  graphics  – Viewing  direc?ons  – Normal  vectors  

– Ray  direc?ons  •  Direc?ons  are  represented  by  vectors,  like  points,  and  can  be  transformed,  but  not  like  points  

(1,1) (-2,-1)

x

y

Page 43: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Transforming  Direc?ons  

•  Say  I  define  a  direc?on  as  the  difference  of  two  points:  d=a–b  – This  represents  the  direc)on  of  the  line  between  two  points  

•  Now  I  transform  the  points  by  the  same  amount:  a’=M*a+t,  b’=M*b+t  

•  d’=a’–b’=M*(a-­‐b)=M*d  

•  Transla?on  does  not  maWer  

Page 44: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Homogeneous  Direc?ons  •  Transla?on  does  not  affect  direc?ons!  •  Homogeneous  coordinates  give  us  a  very  clean  way  of  handling  this  

•  The  direc?on  (x,y)  becomes  the  homogeneous  direc?on  (x,y,0)  

•  M  can  be  any  linear  transforma?on:  rota?on,  scaling,  etc  

Page 45: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Homogeneous  Direc?ons  •  Transla?on  does  not  affect  direc?ons!  •  Homogeneous  coordinates  give  us  a  very  clean  way  of  handling  this  

•  The  direc?on  (x,y)  becomes  the  homogeneous  direc?on  (x,y,0)  

•  M  can  be  any  linear  transforma?on:  rota?on,  scaling,  etc  –  Uniform  scaling  changes  the  length  of  the  vector,  but  not  the  direc?on  

–  How  to  represent  this  equivalence    

Page 46: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Homogeneous  Coordinates  •  In  general,  homogeneous  coordinates  (x,  y,  w)    

•  How  to  interpret  the  case  for  w  =  0?  •  Point  at  infinity:  direc?onal  vector  

•  (1,2,1)    (2,4,2)  •  (2,3,0)    (6,9,0)  

Page 47: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Transforming  Normal  Vector  

•  Why  normal  vectors  are  special?  

Page 48: CS559:&Computer&Graphics&pages.cs.wisc.edu/~lizhang/courses/cs559-2010s/syllabus/02-15-morphing/... · 3D&Graphics&Pipeline& Rendering (Creating, shading images from geometry, lighting,

Transforming  normal  vectors    

tangent normal

tangent’

normal’

M

If M is a rotation,