Learn R Programming

CVXR (version 1.0-14)

tv: Total Variation

Description

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.

Usage

tv(value, ...)

Value

An Expression representing the total variation of the input.

Arguments

value

An Expression, vector, or matrix.

...

(Optional) Expression objects or numeric constants that extend the third dimension of value.

Examples

Run this code
rows <- 10
cols <- 10
Uorig <- 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 corrupted
Known <- matrix(0, nrow = rows, ncol = cols)
for(i in 1:rows) {
   for(j in 1:cols) {
      if(stats::runif(1) > 0.7)
         Known[i,j] <- 1
   }
}
Ucorr <- Known %*% Uorig

# Recover the original image using total variation in-painting
U <- 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)

Run the code above in your browser using DataLab