在活动轮廓法中绘制能量

Draw energy in active contour method

我有一个能量方程,例如

算法由Lankton and you can download the code and image at code实现。我想基于该代码绘制能量函数。请注意,F 是在该代码中计算的。我的目标能量图如

我试着用那个代码来实现它。但不是正确答案

  Energy=[];
  %--main loop
  for its = 1:max_its   % Note: no automatic convergence test

    %-- get the curve's narrow band
    idx = find(phi <= 1.2 & phi >= -1.2)';  
    [y x] = ind2sub(size(phi),idx);

    %-- get windows for localized statistics
    xneg = x-rad; xpos = x+rad;      %get subscripts for local regions
    yneg = y-rad; ypos = y+rad;
    xneg(xneg<1)=1; yneg(yneg<1)=1;  %check bounds
    xpos(xpos>dimx)=dimx; ypos(ypos>dimy)=dimy;

    %-- re-initialize u,v,Ain,Aout
    u=zeros(size(idx)); v=zeros(size(idx)); 
    Ain=zeros(size(idx)); Aout=zeros(size(idx)); 
    F_energy=zeros(size(idx));
    %-- compute local stats
    for i = 1:numel(idx)  % for every point in the narrow band
      img = I(yneg(i):ypos(i),xneg(i):xpos(i)); %sub image
      P = phi(yneg(i):ypos(i),xneg(i):xpos(i)); %sub phi

      upts = find(P<=0);            %local interior
      Ain(i) = length(upts)+eps;
      u(i) = sum(img(upts))/Ain(i);

      vpts = find(P>0);             %local exterior
      Aout(i) = length(vpts)+eps;
      v(i) = sum(img(vpts))/Aout(i);
      F_energy(i)=sum((img(upts)-u(i)).^2)+sum((img(vpts)-v(i)).^2); %% Compute the first term in (5) without integrate
    end   

    %-- get image-based forces
    F = -(u-v).*(2.*I(idx)-u-v);
    % Compute the second term in (5) 
    u=phi<=0;
    bw2=bwperim(u);
    Length_phi=sum(sum(bw2));
    Energy=[Energy (sum(F_energy(:))+alpha.*Length_phi)];
    end

也许是因为能量函数太复杂了所以才这么难。然而,所有的东西都是由上面的代码实现的,除了enrgy term。希望您能理解并帮助我绘制enrgy函数。提前致谢

这是我的数字结果。然而,它与论文结果并不相似。我的结果是在接近零点时能量最小。但是论文结果不是。我的代码中发生了什么。

您确定您的参数与原始论文中使用的参数相似吗?我观察到每次迭代中的能量至少取决于两件事:

  • 半径
  • 初始化掩码

论文确实证实了这种关系:

The radius of the ball selected by the B(x,y) function is an important parameter to be considered when using localized energies.

One limitation of the proposed method is that it has a greater sensitivity to initialization than global region-based methods.

下图显示了我使用您的代码实现的目标:

请注意,在原始论文中,X 轴单位是秒。代码在每次迭代中为我们提供能量。如果不知道原始计算中一次迭代的持续时间(如论文中所述),我们就无法真正比​​较这些图。但是,我的和原来的更相似。

这是初始化掩码的代码(对应于绘图):

I = imread('Mushroom.png');         %-- load the image
m = false(size(I,1),size(I,2));     %-- create initial mask
m(60:100,15:80) = true;             %-- initial mask coordinates

最大迭代次数:400
半径:20

希望我帮到了你。