Total Variation (TV) Norm Function Input: Vector or Matrix?


#1

I am trying to use the CVX toolbox with my own TV norm Matlab function. I know that the TV norm is also known as the “discrete TV seminorm” and that it meets the first three properties of a vector norm; therefore it is convex because all norms are convex. My Matlab function’s input is a matrix (namely, an image); however, from reading CVX the manual it appears that the CVX toolbox works better with vectors; so, can I modify my TV norm function’s inputs to be a vector, number or rows (m) and columns (n), then inside my function convert the vector to an mxn matrix, and then return as the output of my TV norm function, the TV norm of this matrix (image) created from the vector inside my function? I will appreciate any assistance.


How to solve L1-TV formulation
(Michael C. Grant) #2

I see no reason why you can’t use matrix expressions. You’ll need to offer more specifics about exactly what function you’re trying to build. But it seems to me that this is a reasonable implementation of a certain form of the TV function:

norm([vec(X(2:end,:)-X(1:end-1,:));vec(X(:,2:end)-X(:,1:end-1))])

#3

This is my version:

v1=(imageA(2:end,:)-imageA(1:end-1,:));
v2=(imageA(:,2:end)-imageA(:,1:end-1));

v1=reshape(v1,1,[])’;
v2=reshape(v2,1,[])’;

tvnorm=sum(sqrt(v1.^2 + v2.^2));

However, I get a totally different number as when I use your version:

norm([v1;v2])

…or I am probably doing something wrong…?

Is the “norm” function that you use in your example the same as the norm function in Matlab or is this “norm” function a different function only used within CVX commands?


(Michael C. Grant) #4

Well yes, this actually should not work at all in CVX, as it violates the disciplined convex programming ruleset.