gvf_snake.m
资源名称:Snakes.rar [点击查看]
上传用户:zlding2008
上传日期:2013-05-13
资源大小:1914k
文件大小:1k
源码类别:
2D图形编程
开发平台:
Matlab
- function gvf_snake(img)
- I = imread(img);
- I = double(I);
- % Compute its edge map
- disp(' Compute edge map ...');
- f = 1 - I/255;
- % Compute the GVF of the edge map f
- disp(' Compute GVF ...');
- [u,v] = GVF(f, 0.2, 80);
- disp(' Nomalizing the GVF external force ...');
- mag = sqrt(u.*u+v.*v);
- px = u./(mag+1e-10); py = v./(mag+1e-10);
- % display the results
- figure(1);
- subplot(221); imshow(I); title('test image');
- subplot(222); imshow(f); title('edge map');
- % display the gradient of the edge map
- [fx,fy] = gradient(f);
- subplot(223); quiver(fx,fy);
- axis off; axis equal; axis 'ij'; % fix the axis
- title('edge map gradient');
- % display the GVF
- subplot(224); quiver(px,py);
- axis off; axis equal; axis 'ij'; % fix the axis
- title('normalized GVF field');
- % snake deformation
- disp(' Press any key to start GVF snake deformation');
- pause;
- figure(1); subplot(221); cla;
- colormap(gray(256)); image(((1-f)+1)*40); axis('equal', 'off');
- [x,y] = snakeinit(1);
- snakedisp(x,y,'r')
- pause(1);
- for i=1:25,
- [x,y] = snakedeform(x,y,0.05,0,1,0.5,px,py,5);
- [x,y] = snakeinterp(x,y,2,0.5);
- snakedisp(x,y,'r')
- title(['Deformation in progress, iter = ' num2str(i*5)])
- pause(0.5);
- end
- disp(' Press any key to display the final result');
- pause;
- cla;
- colormap(gray(64)); image(((1-f)+1)*40); axis('equal', 'off');
- snakedisp(x,y,'r')
- title(['Final result, iter = ' num2str(i*5)]);