我有一个令人兴奋的等式,如
该算法由Lankton实现,您可以在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之外,所有的东西都是通过上面的代码实现的.希望你能理解并帮助我画出能量函数.预先感谢
这是我的数字结果.但是,它与纸张结果不相似.我的结果是在接近零点时能量最小.但论文的结果并非如此.我的代码中发生了什么.
最佳答案 您确定,您的参数与原始纸张中的参数类似吗?我观察到每次迭代中的能量至少取决于两件事:
>半径
>初始化掩码
该论文确实证实了这种关系:
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
希望我帮了.