510 likes | 521 Views
This recitation covers topics such as least squares approach, general/polynomial fitting, linear systems of equations, and local polynomial surface fitting in computer graphics.
E N D
Computer Graphics Recitation 11
The plan today • Least squares approach • General / Polynomial fitting • Linear systems of equations • Local polynomial surface fitting
Motivation y = f (x) • Given data points, fit a function that is “close” to the points y Pi = (xi, yi) x
Motivation • Local surface fitting to 3D points
Line fitting • Orthogonal offsets minimization – we learned y Pi = (xi, yi) x
Line fitting • The origin of the line is the center of mass • The direction v is the eigenvector corresponding to the largest eigenvalue of the scatter matrix S (22) • In 2D this requires solving a square characteristic equation • In higher dimensions – higher order equations…
Line fitting • y-offsets minimization y Pi = (xi, yi) x
Line fitting • Find a line y = ax + b that minimizes Err(a, b) = [yi – (axi + b)]2 • Err is quadratic in the unknown parameters a, b • Another option would be, for example: • But – it is not differentiable, harder to minimize…
Line fitting – LS minimization • To find optimal a, b we differentiate Err(a, b): Err(a, b) = (–2xi)[yi – (axi + b)] = 0 Err(a, b) = (–2)[yi – (axi + b)] = 0
Line fitting – LS minimization • We get two linear equations for a, b: (–2xi)[yi – (axi + b)] = 0 (–2)[yi – (axi + b)] = 0
Line fitting – LS minimization • We get two linear equations for a, b: [xiyi – axi2 – bxi] = 0 [yi – axi – b] = 0
Line fitting – LS minimization • We get two linear equations for a, b: ( xi2) a + ( xi) b = xiyi ( xi) a + ( 1)b = yi
Line fitting – LS minimization • Solve for a, b using e.g. Gauss elimination • Question: why the solution is minimum for the error function? Err(a, b) = [yi – (axi + b)]2
Fitting polynomials • Decide on the degree of the polynomial, k • Want to fit f(x) = akxk + ak-1xk-1 + … a1x+ a0 • Minimize: Err(a0, a1, …, ak) = [yi – (akxk+ak-1xk-1+ …+a1x+a0)]2 Err(a0,…,ak) = (– 2xm)[yi – (akxk+ak-1xk-1+…+ a0)] = 0
Fitting polynomials • We get a linear system of k+1 in k+1 variables
General parametric fitting • We can use this approach to fit any function f(x) • Specified by parameters a, b, c, … • The expression f(x) linearly depends on the parameters a, b, c, …
General parametric fitting • Want to fit function fabc…(x) to data points (xi, yi) • Define Err(a,b,c,…) = [yi – fabc…(xi)]2 • Solve the linear system
General parametric fitting • It can even be some crazy function like • Or in general:
Solving linear systems in LS sense • Let’s look at the problem a little differently: • We have data points (xi, yi) • We want the function f(x) to go through the points: i =1, …, n: yi = f(xi) • Strict interpolation is in general not possible • In polynomials: n+1 points define a unique interpolation polynomial of degree n. • So, if we have 1000 points and want a cubic polynomial, we probably won’t find it…
Solving linear systems in LS sense • We have an over-determined linear system nk: f(x1) = 1f1(x1) + 2f2(x1) + … + kfk(x1) = y1 f(x2) = 1f1(x2) + 2f2(x2) + … + kfk(x2) = y2 … … … f(xn) = 1f1(xn) + 2f2(xn) + … + kfk(xn) = yn
Solving linear systems in LS sense • In matrix form:
Solving linear systems in LS sense • In matrix form: Av = y
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”:
Finding the LS solution • v Rk • Av Rn • As we vary v, Av varies over the linear subspace of Rnspanned by the columns of A: Av = = 1 + 2 +…+ k 1 2 . . k A1 A2 Ak A1 A2 Ak
Finding the LS solution Av closest to y • We want to find the closest Av to y: y Subspace spanned by columns of A Rn
Finding the LS solution • The vector Av closest to y satisfies: (Av – y) {subspace of A’s columns} column Ai, <Ai, Av – y> = 0 i, AiT(Av – y) = 0 AT(Av – y) = 0 (ATA)v = ATy These are called the normal equations
Finding the LS solution • We got a square symmetric system (ATA)v = ATy(nn) • If A has full rank (the columns of A are linearly independent) then (ATA) is invertible.
Weighted least squares • Sometimes the problem also has weights to the constraints:
Local surface fitting to 3D points • Normals? • Lighting? • Upsampling?
Local surface fitting to 3D points Locally approximate a polynomial surface from points
Fitting local polynomial • Fit a local polynomial around a point P Reference plane P Z Y X
Fitting local polynomial surface • Compute a reference plane that fits the points close to P • Use the local basis defined by the normal to the plane! z y x
Fitting local polynomial surface • Fit polynomial z = p(x,y) = ax2 + bxy + cy2 + dx + ey + f z y x
Fitting local polynomial surface • Fit polynomial z = p(x,y) = ax2 + bxy + cy2 + dx + ey + f z y x
Fitting local polynomial surface • Fit polynomial z = p(x,y) = ax2 + bxy + cy2 + dx + ey + f z x y
Fitting local polynomial surface • Again, solve the system in LS sense: ax12 + bx1y1 + cy12 + dx1 + ey1 + f =z1 ax22 + bx2y2 + cy22 + dx2 + ey2 + f =z1 . . . axn2 + bxnyn + cyn2 + dxn + eyn + f =zn • Minimize ||zi – p(xi, yi)||2
Fitting local polynomial surface • Also possible (and better) to add weights: wi||zi – p(xi, yi)||2, wi > 0 • The weights get smaller as the distance from the origin point grows.
Geometry compression using relative coordinates • Given a mesh: • Connectivity • Geometry – (x, y, z) of each vertex
Geometry compression using relative coordinates • The size of the geometry is large (compared to connectivity) • (x, y, z) coordinates are hard to compress • Floating-point numbers – have to quantize • No correlation
Geometry compression using relative coordinates • Represent each vertex with relative coordinates: average of the neighbours the relative coordinate vector
Geometry compression using relative coordinates • We call them–coordinates: average of the neighbours the relative coordinate vector
Geometry compression using relative coordinates • When the mesh is smooth, the –coordinates are small. • –coordinates can be better compressed.
Geometry compression using relative coordinates • Matrix form to compute the –coordinates:
Geometry compression using relative coordinates • Matrix form to compute the –coordinates: • The same L matrix for y and z… • L is called the Laplacian of the mesh
Geometry compression using relative coordinates • How do we restore the (x, y, z) from the –coordinates? • Need to solve the linear system: Lx = (x)
Geometry compression using relative coordinates Lx = (x) • But: • L is singular • (x) contains quantization error
Geometry compression using relative coordinates Lx = (x) • Solution: choose some anchor vertices whose (x, y, z) position is known (in addition to )
Geometry compression using relative coordinates • We add the anchor vertices to our linear system: L constrained anchor vertices
Geometry compression using relative coordinates • Now we have more equations than unknowns • Solve in least squares sense!