function GVF_algorithm(I,num_iter)
II=I;
I=imresize(I,[64 64]);
[m, n]=size(I);
if(size(I,3)~=1)
I=rgb2gray(I);
end
I=double(I);
f = 1 - I/255;
[u,v] = GVF(f, 0.2,num_iter);
mag = sqrt(u.*u+v.*v);
U = u./(mag+1e-10);
V = v./(mag+1e-10);
figure(1);
subplot(222); imshow(II);
subplot(224);
quiver(U,V);
axis off;
axis equal;
axis 'ij';
title('normalized GVF field');
subplot(222);
imshow(II)
t = 0:0.05:2*pi;
x = m/2 + 20*cos(t);
y = n/2 + 20*sin(t);
[x,y] = interpolate(x,y,2,0.5);
hold on
x = x(:); y = y(:);
plot([x;x(1,1)],[y;y(1,1)],'r','linewidth',2);
hold off
pause(1);
for i=1:num_iter/5,
cla,
imshow(II)
[x,y] = deformation(x,y,0.05,0,1,U,V,5);
[x,y] = interpolate(x,y,3,1);
hold on
x = x(:); y = y(:);
plot([x;x(1,1)],[y;y(1,1)],'r','linewidth',2);
hold off
title([num2str(i*5),' iteration' ])
pause(0.5);
end
cla;
imshow(II);
hold on
x = x(:); y = y(:);
plot([x;x(1,1)],[y;y(1,1)],'r','linewidth',2);
hold off
title('Final result');