matlab - 在事件轮廓法中绘制能量

标签 matlab image-processing plot matlab-figure

我有一个能量方程,例如 enter image description here

算法由Lankton实现您可以在 code 下载代码和图像。 .我想基于该代码绘制能量函数。请注意,F 是在该代码中计算的。我的目标能量图如 enter image description here

我试图通过该代码实现它。但这不是正确答案

  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函数。提前致谢

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

最佳答案

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

  • 半径
  • 初始化掩码

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

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.

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

Results

请注意,在原始论文中,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

希望我帮到了你。

关于matlab - 在事件轮廓法中绘制能量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29063325/

相关文章:

matlab - 为什么写入不相关的文件会导致加载功能如此缓慢?

java - 对于 Django 下基于 matlab 的 java 程序,相同的 cmd 在 shell 中工作,但在 subprocess.Popen() 中不工作

bash - 在 Matlab 中使用 bash shell

java - Java获取图像宽度和高度

php - ImageMagick -- setImageAlphaChannel 不起作用 (php)

mysql - 如何从 matlab 变量(数组/单元格)中选择 mysql 表

image-processing - 找到岩石水位以上的高度

r - 如何跨多个布局区域绘图

r - 将文本框添加到 ggplot2 中的分面包装布局

python - matplotlib 中的正号刻度标签