The total variation of a vector, matrix, or list of matrices. Uses L1 norm of discrete gradients for vectors and L2 norm of discrete gradients for matrices.
methods
tv(value,...)
Arguments
value: An Expression , vector, or matrix.
...: (Optional) Expression objects or numeric constants that extend the third dimension of value.
Returns
An Expression representing the total variation of the input.
Examples
rows <-10cols <-10Uorig <- matrix(sample(0:255, size = rows * cols, replace =TRUE), nrow = rows, ncol = cols)# Known is 1 if the pixel is known, 0 if the pixel was corruptedKnown <- matrix(0, nrow = rows, ncol = cols)for(i in1:rows){for(j in1:cols){if(stats::runif(1)>0.7) Known[i,j]<-1}}Ucorr <- Known %*% Uorig
# Recover the original image using total variation in-paintingU <- Variable(rows, cols)obj <- Minimize(tv(U))constraints <- list(Known * U == Known * Ucorr)prob <- Problem(obj, constraints)result <- solve(prob, solver ="SCS")result$getValue(U)