Reputation: 1485
I have a enrgy equation such as
The algorithm is implement by Lankton and you can download the code and image at code. I want to base on that code to draw the energy function. Note that the F is computed in that code. The my goal energy figure such as
I tried to implement it by that code. But it is not correct answer
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
Maybe it is so difficult task because the energy function is so complex. However, all thing are implemented by above code, except enrgy term. Hope you can understand and help me draw the enrgy function. Thank in advance
This is my figure result. However, it is not similar the paper result. My result is minimal energy at near zero points. But the paper result is not. What is happen in my code.
Upvotes: 4
Views: 555
Reputation: 428
Are you sure, that your parameters are similar to these used in original paper? I've observed that energy in each iteration depends on at least two things:
The paper indeed confirms that relationship:
The radius of the ball selected by the B(x,y) function is an important parameter to be considered when using localized energies.
and
One limitation of the proposed method is that it has a greater sensitivity to initialization than global region-based methods.
Following picture shows what I've managed to achieve using your code:
Please notice, that in original paper the X-axis unit is second. The code gives us energy in each iteration. Without knowing the duration of one iteration in the original computations (described in the paper) we can't really compare these plots. However, mine is much more similar to the original one.
Here is code for the initialization mask (corresponding to the plot):
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
Max iterations: 400
Radius: 20
Hope I've helped.
Upvotes: 2