G22.2274 Fall Advanced Computer Graphics
Transcript of G22.2274 Fall Advanced Computer Graphics
G22.2274‐001, Fall 2010
Advanced Computer Graphics
Project details and tools
9/20/2010 1Olga Sorkine, Courant Institute
Projects
Details of each project are on the website under “Projects”
Please review all the projects and come see me if you would like to discuss details.
9/20/2010 Olga Sorkine, Courant Institute 2
Project Topics
Computer Animation
Interactive Shape Modeling
Computational PhotographyImage Processing
9/20/2010 3Olga Sorkine, Courant Institute
Code TipsSee links on the ‘Resources’ webpage!
For projects involving 2D only:You can use MATLAB and/or OpenCV
Not much UI involved
For projects in 3DI recommend OpenGL rendering with GLUT
For GUI you can use AntTweakBar or GLUI
If familiar: QT or other GUI APIs (more heavy‐weight)
Mesh libraries: see course website. Again, preference for light‐weight (trimesh).
9/20/2010 Olga Sorkine, Courant Institute 4
Optimization
Almost all projects have a global optimization component:
Define some energy functional E(x)x is the shape, or the image…
Compute the optimal x such that E(x) is minimized
There are some constraints to the minimization
9/20/2010 5Olga Sorkine, Courant Institute
Computer AnimationCharacter animation
Create a system for rigging and posing of digital characters (shapes)
Step 1: compute a skeleton
9/20/2010 6Olga Sorkine, Courant Institute
Computer AnimationCharacter animation
Create a system for rigging and posing of digital characters (shapes)
Step 1: compute a skeletonSuggestion: implement the paper “Skeleton Extraction by Mesh Contraction”, SIGGRAPH 2008
also implement GUI to manually create a skeleton
9/20/2010 7Olga Sorkine, Courant Institute
Computer AnimationCharacter animation
Function E(x) measures how smooth the shape x is
Constraints: extremities (finger tips, ears, etc.)
∑ ∑= ∈
−=n
i iNjjiji w
1
2
)()(E xxx
9/20/2010 8Olga Sorkine, Courant Institute
Geometric ModelingInteractive shape editing system
Implement one of the recent papers:“PriMo”, SGP 2006
The objective functional E(x) says the details of the shape should be preserved as much as possible
The constraints for the minimization are the user‐defined fixed positions
9/20/2010 9Olga Sorkine, Courant Institute
Interactive Shape ModelingSketch‐based modeling
Inflation of 2D sketches into a 3D shape
Objective E(x) measures how smooth the surface x is
The constraint is the silhouette curve
9/20/2010 Olga Sorkine, Courant Institute 10
User draws the silhouette
System meshes the interior
System inflatesthe shape
Implement a system for 3D painting on surfaces
Color from a curve is diffused by means of the Poisson equation
E(x) says the color field xshould be smooth
Constraints: colors of the curves
9/20/2010 Olga Sorkine, Courant Institute 11
Interactive Shape ModelingSketch‐based painting: diffusion curves on surfaces
Computational PhotographyShaky cam stabilization
Implement “Content‐Preserving Warps for 3D Video Stabilization”, SIGGRAPH 2009”
9/20/2010 12Olga Sorkine, Courant Institute
Computational PhotographyShaky cam stabilization
Implement “Content‐Preserving Warps for 3D Video Stabilization”, SIGGRAPH 2009”
E(x) measures:How well the quads are preserved(want all angles to be 90)
Constraints: point‐to‐point(match new projected position to the old position)
9/20/2010 13Olga Sorkine, Courant Institute
Image ProcessingImage retargeting (resizing)
The problem: resize an image to fit a display device with a different aspect ratio
9/20/2010 14Olga Sorkine, Courant Institute
Image ProcessingImage retargeting (resizing)
The problem: resize an image to fit a display device with a different aspect ratio
9/20/2010 15Olga Sorkine, Courant Institute
Image ProcessingImage retargeting (resizing)
Approach:Compute an importance map of the image
Warp the image such that regions with high importance are preserved at the expense of unimportant regions
importance map
9/20/2010 16Olga Sorkine, Courant Institute
Grid mesh, preserve the shape of the important quads
Optimize the location of mesh vertices, interpolate image
quads with high importance:uniform scaling
quads with low importance:allowed non‐uniform scaling
Image ProcessingImage retargeting (resizing)
9/20/2010 17Olga Sorkine, Courant Institute
Grid mesh, preserve the shape of the important quads
Optimize the location of mesh vertices, interpolate image
Image ProcessingImage retargeting (resizing)
9/20/2010 18Olga Sorkine, Courant Institute
Grid mesh, preserve the shape of the important quads
Optimize the location of mesh vertices, interpolate image
Image ProcessingImage retargeting (resizing)
9/20/2010 19Olga Sorkine, Courant Institute
E(x) measures:How well the quad shape is preserved
How smooth the grid lines are
Constraints:The boundary of the image(has to fit new dimensions)
Cropping constraints: all important content shouldremain in the resulting image
Image ProcessingImage retargeting (resizing)
9/20/2010 20Olga Sorkine, Courant Institute
Optimization
In the projects:mostly linear optimization, i.e.linear least‐squares problems
9/20/2010 21Olga Sorkine, Courant Institute
Solving linear systems in LS sense
Wish list of equations:
∀i =1, …, n: f (xi) = fi
Example: measuring surface smoothness
∑ ∑= ∈
−=n
i iNjjiji w
1
2
)()(E xxx
9/20/2010 22Olga Sorkine, Courant Institute
Solving linear systems in LS sense
Wish list of equations:
∀i =1, …, n: f (xi) = fi
Example: measuring surface smoothness
∑ ∑= ∈
−=n
i iNjjiji w
1
2
)()(E xxx
0:,,1)(
=−=∀ ∑∈ iNj
jiji wni xxK Wish equation
9/20/2010 23Olga Sorkine, Courant Institute
Solving linear systems in LS sense
We have an over‐determined linear system k × n:
a11 x1 + a12 x2 + … + a1n xn = b1
a21 x1 + a22 x2 + … + a2n xn = b2
…ak1 x1 + ak2 x2 + … + akn xn = bk
9/20/2010 24Olga Sorkine, Courant Institute
Solving linear systems in LS sense
In matrix form:
⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜⎜
⎝
⎛
kknkk
n
n
aaa
aaaaaa
b
bb
2
1
21
22221
11211
M
K
MMM
K
K
K
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
nx
xx
2
1
M
9/20/2010 25Olga Sorkine, Courant Institute
Solving linear systems in LS sense
In matrix form:
Ax = bwhere A = (aij) is a rectangular k×n matrix, k > n
x = (x1, x2, …, xn)T b = (b1, b2, …, bk)T
9/20/2010 26Olga Sorkine, Courant Institute
Solving linear systems in LS sense
More constrains than variables – no exact solutions generally exist
We want to find something that is an “approximate solution”:
xopt = argmin ||Ax – b||2
min E(x)
x
x
9/20/2010 27Olga Sorkine, Courant Institute
Finding the LS solution
x ∈ Rn
Ax ∈ Rk
As we vary x, Ax varies over the linear subspace of Rk spanned by the columns of A:
Ax = A2A1 An
x1x2..
xn
= x1 A1 A2 An+ x2 +… + xn
9/20/2010 28Olga Sorkine, Courant Institute
Finding the LS solution
We want to find the closest Ax to b: min ||Ax – b||2
Subspace spannedby columns of A
b
Rk
Axclosest to b
x
9/20/2010 29Olga Sorkine, Courant Institute
Finding the LS solution
The vector Ax closest to b satisfies:(Ax – b) ⊥ {subspace of A’s columns}
∀ column Ai: ⟨Ai, Ax – b⟩ = 0
∀ i, AiT(Ax – b) = 0
AT(Ax – b) = 0(ATA)x = ATb
These arecalled the
normal equations
9/20/2010 30Olga Sorkine, Courant Institute
Finding the LS solution
We got a square symmetric system (ATA)x = ATb
(n×n)
If A has full rank (the columns of A are linearly independent) then (ATA) is invertible.
( ) bx
bx
T1T
2
x
AAA
Amin
−=
⇓
−
9/20/2010 31Olga Sorkine, Courant Institute
Weighted least squares
If each constraint has a weight in the energy:
The weights wi > 0 and don’t depend on xThen:
min (Ax – b)T W(Ax – b) where W = (wi)ii
(AT W A) x = AT W b
∑=
−n
1
2))(f(mini
iiiiw bxx
9/20/2010 32Olga Sorkine, Courant Institute
Linear Systems
Matrix is often fixed, rhs changes
M x = r
ATA bAT
9/20/2010 33Olga Sorkine, Courant Institute
Matrix FactorizationLU decomposition
M = LU
Mx = rLUx = r
9/20/2010 34Olga Sorkine, Courant Institute
Matrix FactorizationLU decomposition
M = LU
Mx = rL(Ux) = r
9/20/2010 35Olga Sorkine, Courant Institute
Matrix FactorizationLU decomposition
M = LU
Mx = rL(Ux) = r
Ly = rUx = y
This is backsubstitution.If L, U are sparse it is very fast. The hard work is computing L and U
9/20/2010 36Olga Sorkine, Courant Institute
Matrix FactorizationLU decomposition
M = LU
Mx = rL(Ux) = r
y = L–1rx = U–1y
This is backsubstitution.If L, U are sparse it is very fast. The hard work is computing L and U
9/20/2010 37Olga Sorkine, Courant Institute
Matrix FactorizationCholesky decomposition
M = LLT
Cholesky factor exists if M is positive definite. It is even better than LU because we save memory.
9/20/2010 38Olga Sorkine, Courant Institute
Cholesky Decomposition
M is symmetric positive definite (SPD):
∀ x≠0, ⟨Mx, x⟩ > 0 ⇔ all M’s eigenvalues > 0
M = LLT
M = LLT
9/20/2010 39Olga Sorkine, Courant Institute
Dense Cholesky Factorization
M = LLT
500×500 matrix3500 nonzeros
L36k nonzeros
Cholesky Factorization
9/20/2010 40Olga Sorkine, Courant Institute
Sparse Cholesky Factorization
M = LLT
500×500 matrix3500 nonzeros
L36k nonzeros
Cholesky Factorization
Reordering
PMPTreverse Cuthill‐McKee algorithm
9/20/2010 41Olga Sorkine, Courant Institute
M = LLT
500×500 matrix3500 nonzeros
L36k nonzeros
Cholesky Factorization
Reordering
PMPTreverse Cuthill‐McKee algorithm
L14k nonzeros
Sparse Cholesky Factorization
9/20/2010 42Olga Sorkine, Courant Institute
Sparse Cholesky Factorization
M = LLT
500×500 matrix3500 nonzeros
L36k nonzeros
Cholesky Factorization
Reordering
PMPTnested dissection(parallelizable)
9/20/2010 43Olga Sorkine, Courant Institute
Sparse Cholesky Factorization
M = LLT
500×500 matrix3500 nonzeros
L36k nonzeros
Cholesky Factorization
Reordering
PMPTnested dissection(parallelizable)
L7k nonzeros
9/20/2010 44Olga Sorkine, Courant Institute
Direct SolversDiscussion
Highly accurateManipulate matrix structure
No iterations, everything is closed‐form
Easy to useOff‐the‐shelf library, no parameters
If M stays fixed, changing rhs (r) is cheapJust need to back‐substitute (factor precomputed)
9/20/2010 45Olga Sorkine, Courant Institute
Direct SolversDiscussion
High memory costNeed to store the factor, which is typically denser than the matrix M
If the matrix M changes, need to re‐compute the factor (expensive)
9/20/2010 46Olga Sorkine, Courant Institute
TAUCS tutorial
TAUCS: a library of sparse linear solversHas both iterative and direct solvers
Direct (Cholesky and LU) use reordering and are very fast
I provide a wrapper for TAUCS on the course homepage
9/20/2010 47Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Define a sparse matrix structure
Fill the matrix with its nonzero values (i, j, v)
Factor ATA
Provide an rhs and solve
9/20/2010 48Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Define a sparse matrix structure
InitTaucsInterface();
int idA;idA = CreateMatrix(4, 3);
#rows #cols
9/20/2010 49Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Fill the matrix A with its nonzero values (i, j, v)
SetMatrixEntry(idA, i, j, v);
9/20/2010 50Olga Sorkine, Courant Institute
TAUCS tutorial
SetMatrixEntry(idA, i, j, v);
matrix ID, obtained in CreateMatrix
Basic operations:Fill the matrix A with its nonzero values (i, j, v)
9/20/2010 51Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Fill the matrix A with its nonzero values (i, j, v)
SetMatrixEntry(idA, i, j, v);
row index i, column index j,zero‐based
9/20/2010 52Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Fill the matrix A with its nonzero values (i, j, v)
SetMatrixEntry(idA, i, j, v);
value of matrix entry ijfor instance, –wij
9/20/2010 53Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Factor the matrix ATA
FactorATA(idA);
9/20/2010 54Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
9/20/2010 55Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
typedef for double
9/20/2010 56Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
ID of the A matrix
9/20/2010 57Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
rhs for the LS system Ax = b
9/20/2010 58Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
array for the solution
9/20/2010 59Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b[4] = {3, 4, 5, 6};taucsType x[3];
SolveATA(idA, b, x, 1);
number of rhs’s
A is 4x3
9/20/2010 60Olga Sorkine, Courant Institute
TAUCS tutorial
Basic operations:Provide an rhs and solve
taucsType b2[8] = {3, 4, 5, 6, 7, 8, 9, 10};taucsType xy[6];
SolveATA(idA, b2, xy, 2);
number of rhs’s
A is 4x3
9/20/2010 61Olga Sorkine, Courant Institute
TAUCS tutorial
If the matrix A is square a priori, no need to solve the LS systemThen just use FactorA()and SolveA()
9/20/2010 62Olga Sorkine, Courant Institute
Further Reading
Efficient Linear System Solvers for Mesh Processing Mario Botsch, David Bommes, Leif KobbeltInvited paper at IMA Mathematics of Surfaces XI, Lecture Notes in Computer Science, Vol 3604, 2005, pp. 62‐83.
9/20/2010 63Olga Sorkine, Courant Institute
Next week
By September 27 you must:Read up on all the projects and decide on your priorities
Discuss with me if you’d like to do a customized project (your own ideas)
E‐mail me your project preference (ranked list)
No class meeting (do homework! ☺ )
9/20/2010 64Olga Sorkine, Courant Institute
Next week and after
On September 28 I will assign a project to everyoneNext class: October 4; everyone presents their initial project planUp to 20 minutes presentation (can be shorter)
Explain the project in your words, with technical detailsOutline your work planBring up things that are unclear/challenges you foresee
9/20/2010 65Olga Sorkine, Courant Institute