4
$\begingroup$

TV is L1 norm of gradient of an image. So we've to find gradient of the image (which is still matrix, right?). Then take the sum of absolute values of the gradient matrix (So now it must be a scalar, right?).

Can I simply use imgradient function in matlab for first step? It gives two values magnitude and direction, so which one should I consider for next step?

After getting gradient matrix say Igrad, will just summing absolute values (sum(abs(Igrad(:))) give me TV? And it must be just a single scalar value right?

Thank you for reading. Keenly waiting for your reply.

$\endgroup$

2 Answers 2

7
$\begingroup$

The Total Variation of an image $I$ can be computed using two formulas:

  • $TV(I) = \sum_{x} \| \nabla I (x) \|_1 $ (anisotropic TV);
  • $TV(I) = \sum_{x} \sqrt{ \| \nabla I (x) \|_2^2 }$ (isotropic TV).

In practice, both formulas yield almost the same result.

Using matlab, what you propose implements the first formula, while the second one can be obtained by sqrt(gradI_x.^2 + gradI_y.^2).

$\endgroup$
4
  • $\begingroup$ Thank you for your reply. I have one more query. Since the result of TV is scalar how are we adding it as a regularization term in many image restoration problems? Because images and other parameters are matrices. I don't know if this is proper place to ask this. Anyway thanks again $\endgroup$
    – akhilc
    Commented May 15, 2014 at 16:05
  • $\begingroup$ Two solutions that have the same data fidelity score will probably have different TV score. Thus, among the possible solutions, the one with the lowest TV is kept. $\endgroup$
    – sansuiso
    Commented May 15, 2014 at 20:53
  • $\begingroup$ I have a related inquiry. How can we calculate DTV (differential total variation) using Matlab? $\endgroup$ Commented Sep 1, 2018 at 2:56
  • $\begingroup$ @Mohammadnagdawi, Have a look on my answer here - dsp.stackexchange.com/a/57985/128. There is a MATLAB code. $\endgroup$
    – Royi
    Commented Oct 19, 2019 at 20:58
0
$\begingroup$

can use MATLAB function imgradientxy.

[Gx,Gy] = imgradientxy(I).

This will return the x and y derivative of image I.

$\endgroup$
1
  • $\begingroup$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Commented Aug 4, 2022 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.