Faculty of Science, University of Copenhagen
Stefan Sommer
Department of Computer Science, University of Copenhagen
\( \phi \)
Session 1: (L 9-9:45) Shape analysis and actions of the diffeomorphism group
Session 2: (E 10-10:45) Landmark analysis in Theano Geometry
Session 3: (L 11-11:45) Linear representations and random orbit model
Session 4: (E 12:30-13:15) Landmarks statistics in Theano Geometry
Session 5: (L 13:30-14:15) Shape spaces of images, curves and surfaces
Session 6: (E 14:30-15:15) Analysis of continuous shapes
Slides: https://slides.com/stefansommer/shape-analysis-X/ (X=1,2,3)
Objects on which the diffeomorphism group acts
\(d=2,3\)
move analysis from
treat all shape types with in one framework
LDDMM: Large Deformation Diffeomorphic Metric Mapping
Grenander, Christensen, Trouve, Younes, Miller, Joshi, Holm, etc.
\( \phi \)
\( \phi \)
\(\phi\) deformation of domain \(\Omega\)
action: shape follows deformation
\(G = \mathrm{Diff}(\Omega)\)
\(\phi\in G\): smooth (\(C^k\)), invertible, smooth inverse
Actions:
shape \(s\) (e.g. \(s=\mathbf{q}\) or \(s=I\))
left actions satisfy
Landmark action:
\( \phi\in\mathrm{Diff}(\Omega) \) diffeomorphism of domain \(\Omega\)
\( \phi \)
Variational problem to find optimal \(\phi\in G\):
\[ \frac{d}{dt} q = \quad \frac{\partial H(q,p)}{\partial p} \]
\[ \frac{d}{dt} p = -\frac{\partial H(q,p)}{\partial q} \]
LDDMM landmark matching:
\[ \frac{d}{dt} q = \quad \frac{\partial H(q,p)}{\partial p} \]
\[ \frac{d}{dt} p = -\frac{\partial H(q,p)}{\partial q} \]
Geodesics for Riemannian metric on landmark shape space:
\[ \frac{d}{dt} q = \quad \frac{\partial H(q,p)}{\partial p} \]
\[ \frac{d}{dt} p = -\frac{\partial H(q,p)}{\partial q} \]
LDDMM landmark matching:
Hamiltonian:
\[ H(q,p) = \sum_{i,j=1}^n p_i^TK(x_i,x_j)p_j\]
\(K\) RKHS kernel, e.g. \(K(q_i,q_j)=\alpha e^{-\frac{\|q_i-q_j\|^2}{2\sigma^2}}\)
Hamiltonian:
\[ H(q,p) = \sum_{i,j=1}^n p_i^TK(q_i,q_j)p_j\]
\(K\) RKHS kernel, e.g. \(K(q_i,q_j)=\alpha e^{-\frac{\|q_i-q_j\|^2}{2\sigma^2}}\)
Entire evolution \((q(t),p(t)\) determined by \((q_0,p_0)\) or \((q_0,v_0)\), \(v_0=Kp_0\)
x = T.tensor3('x')
# landmark RKHS kernel
def K(q1,q2):
r_sq = T.sqr(q1.dimshuffle(0,'x',1)-q2.dimshuffle('x',0,1)).sum(2)
return T.exp( - r_sq / (2.*sigma**2) )
#Hamiltonian
def H(q,p):
return 0.5*T.tensordot(p,T.tensordot(K(q,q),p,[[1],[0]]),[[0,1],[0,1]])
# Hamiltons equations
dq = lambda q,p: T.grad(H(q,p),p)
dp = lambda q,p: -T.grad(H(q,p),q)
# ODE
def ode_f(x):
dqt = dq(x[0],x[1])
dpt = dp(x[0],x[1])
return T.stack((dqt,dpt))
# Euler step
def euler(x,dt):
return x+dt*ode_f(x)
# Euler integration: symbolic loop
(cout, updates) = theano.scan(fn=euler,outputs_info=[x],non_sequences=[dt],
n_steps=n_steps)
# compile it
simf = function(inputs=[x],outputs=cout,updates=updates)
# and loss function for matching
loss = 1./N*T.sum(T.sqr(cout[-1,0]-qtarget0))
# gradient
dloss = T.grad(loss,x)
# compile
lossf = function(inputs=[x],outputs=loss,updates=updates)
dlossf = function(inputs=[x],outputs=[loss, dloss],updates=updates)
# shooting
from scipy.optimize import minimize,fmin_bfgs,fmin_cg
def shoot(q0,p0):
def fopts(x):
[y,gy] = dlossf(np.stack([q0,x.reshape([N.eval(),DIM])]).astype(theano.config.floatX),)
return (y,gy[1].flatten())
res = minimize(fopts, p0.flatten(), method='L-BFGS-B', jac=True)
return(res.x,res.fun)
# # This file is part of Theano Geometry
#
# ...
from src.setup import *
from src.utils import *
###############################################################
# geodesic integration, Hamiltonian form #
###############################################################
def initialize(M):
q = M.coords()
p = M.coordscovector()
dq = lambda q,p: T.grad(M.H(q,p),p)
dp = lambda q,p: -T.grad(M.H(q,p),q)
def ode_Hamiltonian(t,x):
dqt = dq(x[0],x[1])
dpt = dp(x[0],x[1])
return T.stack((dqt,dpt))
M.Hamiltonian_dynamics = lambda q,p: integrate(ode_Hamiltonian,T.stack((q,p)))
M.Hamiltonian_dynamicsf = theano.function([q,p], M.Hamiltonian_dynamics(q,p))
## Geodesic
M.Exp_Hamiltonian = lambda q,p: M.Hamiltonian_dynamics(q,p)[1][-1,0]
M.Exp_Hamiltonianf = theano.function([q,p], M.Exp_Hamiltonian(q,p))
Exercise session:
Slides: https://slides.com/stefansommer/shape-analysis-X/ (X=1,2,3)