在matlab中实现Chambolle双配方法

时间:2015-07-10 16:17:04

标签: algorithm matlab image-processing optimization computer-vision

我想实施Chambolle双配方法。该方法可以总结如下    enter image description here

这是我在matlab中的实现。但是,它没有给出真实的结果。你能看到吗,请给我一些关于该代码的意见/建议

    %% Note that div, grad is written correctly. d is given
     u=rand(row,col,dim);
     a=sum(u,3);
     N=2;
     for k = 1 : N
        u(:,:,k)=u(:,:,k)./a;            
    end
    v=zeros(size(I)); %I is image
    for i=1: numIter
    for ii=1:N 
    grad_E = d(:,:,ii);    
    % solve for u
    p1 = zeros([size(u(:,:,1)) N]);
    p2 = zeros([size(u(:,:,1)) N]);
    for j = 1:5
        %% Compute Eq 24
        [d1 d2] = grad(div(p1(:,:,ii),p2(:,:,ii))-u(:,:,ii)/(theta*gamma)); 
        Nu = 1+tau*sqrt(d1.^2+d2.^2);
        p1(:,:,ii) = (p1(:,:,ii) + tau*d1)./Nu;
        p2(:,:,ii) = (p2(:,:,ii) + tau*d2)./Nu;
    end % end of inner iteration
    v = u(:,:,ii) - theta*gamma*div(p1(:,:,ii),p2(:,:,ii)); %% Eq 23
    % solve for v
    u(:,:,ii) = min(max(((v-theta*gamma*grad_E-theta*lambda*gamma*(sum(u(:,:,1:size(u,3) ~= ii),3)-1))...
        ./(1+theta*gamma)),0),1); % Eq 25
    end
    end

1 个答案:

答案 0 :(得分:1)

您可能没有正确实现div和grad。他们需要互补,例如使用渐变的前向差异和div的后向差异。在Toolbox image中查看div和grad的实现。