For data on a dimensional grid this function returns the gradient of the first and second order total variation additive mid point model. The model is explained here and was developed in [1]. Since the model consists of the three terms
The gradient is given by the gradient of the squared distance, the gradient of total variation, and the gradient of second order total variation, where this model uses the mid point formulation.
Optional Parameters
epsilon
 relax the TV (especially for by replacing any distance by and for each inner sum (over ) is relaxed to avoid subgradients in constant areas.
p
 denotes the outer coupling of the differences
Matlab Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
% gradientSecondOrderLog(M,f,alpha,beta)  compute the gradient of
% d(x,f)^2 + alpha*TV(x) + beta*TV2(x), where TV(x) is d(x_i,x_i+1) and
% the second order terms are given by log_x_i x_i1 + log_x_i x_i+1 
%
% INPUT
% M : a manifold
% f : given (original) data
% x : value to take the gradient at
% alpha : weight of TV
% beta : weight of TV2
%
% OPTIONAL
% 'p : (p=1) compute TV with pnorm coupling in the dimensions of the
% data, i.e. anisotropic TV for p=1 and isotropic for p=2
% epsilon : compute the gradient of the epsilonrelaxed TV
% 
% MVIRT  R. Bergmann, 20171207
See also
References

Bačák, M, Bergmann, R, Steidl, G and Weinmann, A (2016). A second order nonsmooth variational model for restoring manifoldvalued images. SIAM Journal on Scientific Computing. 38 A567–A597
We introduce a new nonsmooth variational model for the restoration of manifoldvalued data which includes second order differences in the regularization term. While such models were successfully applied for realvalued images, we introduce the second order difference and the corresponding variational models for manifold data, which up to now only existed for cyclic data. The approach requires a combination of techniques from numerical analysis, convex optimization and differential geometry. First, we establish a suitable definition of absolute second order differences for signals and images with values in a manifold. Employing this definition, we introduce a variational denoising model based on first and second order differences in the manifold setup. In order to minimize the corresponding functional, we develop an algorithm using an inexact cyclic proximal point algorithm. We propose an efficient strategy for the computation of the corresponding proximal mappings in symmetric spaces utilizing the machinery of Jacobi fields. For the \(n\)sphere and the manifold of symmetric positive definite matrices, we demonstrate the performance of our algorithm in practice. We prove the convergence of the proposed exact and inexact variant of the cyclic proximal point algorithm in Hadamard spaces. These results which are of interest on its own include, e.g., the manifold of symmetric positive definite matrices.@article{BBSW16, author = {Ba{\v{c}}{\'a}k, Miroslav and Bergmann, Ronny and Steidl, Gabriele and Weinmann, Andreas}, title = {A second order nonsmooth variational model for restoring manifoldvalued images}, journal = {SIAM Journal on Scientific Computing}, year = {2016}, volume = {38}, number = {1}, pages = {A567A597}, doi = {10.1137/15M101988X}, eprint = {1506.02409}, eprinttype = {arXiv} }