필터 지우기
필터 지우기

Is this the correct implementation of the total variation algorithm?

조회 수: 4 (최근 30일)
S.
S. 2014년 8월 29일
I need to compute the total variation of an image based on the algorithm presented here
I have implemented the following code using the l1 norm of the spatial fist-order derivatives:
function TV = compute_total_variation1(y)
% y is the image
nbdims = 2;
% check number of channels in an image
if size(y,1)==1 || size(y,2)==1
% we have one dimension
nbdims = 1;
end
if size(y,1)>1 && size(y,2)>1 && size(y,3)>1
% we have three dimensions
nbdims = 3;
end
if nbdims==1
TV = sum(abs(diff(y)));
return;
end
% the total variation weight is 1
% weight_tv = ones(size(y));
[gx gy] = gradient(y);
% compute using the l1 norm of the first order derivatives
% horizontal
TVgx = sum( abs(gx),nbdims+1);
% vertical
TVgy = sum( abs(gy),nbdims+1);
% TV = TV .* weight_tv;
TV = sum(TVgx(:)) + sum(TVgy(:));
Is the above implementation valid or not?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by