deform_action = lgd.MatrixImageAffineAction(lie_grp, space) else: assert False # Define what regularizer to use regularizer = 'point' if regularizer == 'image': # Create set of all points in space W = space.tangent_bundle w = W.element(space.points().T) # Create regularizing functional regularizer = 0.1 * odl.solvers.L2NormSquared(W).translated(w) # Create action regularizer_action = lgd.ProductSpaceAction(deform_action, W.size) elif regularizer == 'point': W = odl.ProductSpace(odl.rn(space.ndim), 3) w = W.element([[0, 0], [0, 1], [1, 0]]) # Create regularizing functional regularizer = 0.01 * odl.solvers.L2NormSquared(W).translated(w) # Create action if lie_grp_type == 'affine' or lie_grp_type == 'rigid': point_action = lgd.MatrixVectorAffineAction(lie_grp, W[0]) else: point_action = lgd.MatrixVectorAction(lie_grp, W[0]) regularizer_action = lgd.ProductSpaceAction(point_action, W.size) elif regularizer == 'determinant': W = odl.rn(1)
grid = space.element( lambda x: np.cos(x[0] * np.pi * 5)**20 + np.cos(x[1] * np.pi * 5)**20) # Create regularizing functional # regularizer = 3 * odl.solvers.KullbackLeibler(space, prior=w) regularizer = 0.5 * (odl.solvers.L2NormSquared(space) * weighting).translated(w) # Create action regularizer_action = lgd.JacobianDeterminantScalingAction(lie_grp, space) # Initial guess g = lie_grp.identity # Combine action and functional into single object. action = lgd.ProductSpaceAction(deform_action, regularizer_action, geometric_deform_action) x = action.domain.element([template, w, grid]).copy() f = odl.solvers.SeparableSum(data_matching, regularizer, odl.solvers.ZeroFunctional(space)) # Show some results, reuse the plot template.show('template') target.show('target') # Create callback that displays the current iterate and prints the function # value callback = odl.solvers.CallbackShow('diffemorphic matching', step=20) callback &= odl.solvers.CallbackPrint(f) # Smoothing filter_width = 0.5 # standard deviation of the Gaussian filter
v1 *= 1.5 / v1.norm() f1 = odl.solvers.L2NormSquared(r3).translated(v1) w1 = W.element([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) f2 = 0.2 * odl.solvers.L2NormSquared(W).translated(w1) # SELECT GLn or SOn here # lie_grp = GLn(3) # lie_grp = lgd.SOn(3) # point_action = lgd.MatrixVectorAction(lie_grp, r3) lie_grp = lgd.AffineGroup(3) point_action = lgd.MatrixVectorAffineAction(lie_grp, r3) assalg = lie_grp.associated_algebra power_action = lgd.ProductSpaceAction(point_action, 3) # Combine action and functional into single object. action = lgd.ProductSpaceAction(point_action, power_action) x = action.domain.element([v0, w1]) f = odl.solvers.SeparableSum(f1, f2) # Initial guess g = lie_grp.identity # Create some plotting info fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlim(-2, 2) ax.set_ylim(-2, 2) ax.set_zlim(-2, 2)