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.

tv(value, ...)

## Arguments

value

An Expression, vector, or matrix.

...

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

## Value

An Expression representing the total variation of the input.

## Examples

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)
#>           [,1]     [,2]     [,3]     [,4]     [,5]      [,6]     [,7]     [,8]
#>  [1,] 234.9997 313.3989 312.9316 310.0624 297.7206 281.67540 281.6372 281.6420
#>  [2,] 415.0004 314.2509 314.2820 311.1917 297.7849  71.00007 281.6380 282.0223
#>  [3,] 227.0000 314.2164 318.0012 316.6359 314.7365 308.74584 298.2521 284.4686
#>  [4,] 341.3546 323.1293 320.5015 318.2862 316.4877 316.48709 316.4871 290.0075
#>  [5,] 436.9990 333.8274 327.3164 321.3042 316.4896 316.48879 464.9997 320.1619
#>  [6,] 345.9533 342.7881 337.6808 329.5230 316.4942 172.99978 244.0002 320.1616
#>  [7,] 346.9282 346.9284 346.9265 346.9249 346.0133 346.02251 345.1421 342.9900
#>  [8,] 346.9297 346.9293 346.9260 348.7559 346.0025 348.86537 349.9338 342.9909
#>  [9,] 346.9315 346.9333 424.9979 383.9993 384.2449 384.33258 472.9997 342.9932
#> [10,] 346.9315 346.9333 424.9979 458.0003 549.9994 384.33258 642.0010 342.9932
#>           [,9]    [,10]
#>  [1,] 280.9993 280.9993
#>  [2,] 280.9914 280.9914
#>  [3,] 280.9968 280.9968
#>  [4,] 280.9999 286.9999
#>  [5,] 320.1628 320.1628
#>  [6,] 320.1629 320.1629
#>  [7,] 342.9909 342.9909
#>  [8,] 342.9911 360.9999
#>  [9,] 342.9964 342.9964
#> [10,] 342.9995   0.0000