## 二、部分源代码

clc; clear all; close all;rand('state', 0);warning off all;path([pwd '\\toolbox'], path);filename = 'chest'; % 待处理图像名称% 载入图像[I, map] = rawread(sprintf('images\\%s.pgm', filename));% 计算边缘图像f = 1 - I/255;% GVF处理[u,v] = GVF(f, 0.1, 80);% 正规化处理mag = sqrt(u.*u+v.*v);px = u./(mag+1e-10); py = v./(mag+1e-10);% 显示结果figure(1);subplot(1, 2, 1); imdisp(I); title('原图像', 'FontWeight', 'Bold');subplot(1, 2, 2); imdisp(f); title('边缘图像', 'FontWeight', 'Bold');% 初始边缘曲线load(sprintf('.\\images\\%s.mat', filename));[x,y] = snakeinterp(XSnake,YSnake,2,0.5);subplot(1, 2, 1); hold on;h = plot(x, y, 'r-');% GVF迭代load(sprintf('.\\images\\test_%s.mat', filename));for i=1:25,    [x,y] = snakedeform(x,y,alpha,beta,gamma,kappa,fx,fy,5);    [x,y] = snakeinterp(x,y,dmax,dmin);    set(h, 'XData', x, 'YData', y);    title(['迭代过程，迭代次数为 = ' num2str(i*5)], 'FontWeight', 'Bold')    pause(0.2);endtitle('GVF Snake边缘提取标记', 'FontWeight', 'Bold')mag = sqrt(u.*u+v.*v);px = u./(mag+1e-10); py = v./(mag+1e-10);% 显示结果figure(1);subplot(1, 2, 1); imdisp(I); title('原图像', 'FontWeight', 'Bold');subplot(1, 2, 2); imdisp(f); title('边缘图像', 'FontWeight', 'Bold');% 初始边缘曲线load(sprintf('.\\images\\%s.mat', filename));[x,y] = snakeinterp(XSnake,YSnake,2,0.5);% XSnake% YSnake% GVF snake (active contour) toolbox% Version 1.0 17-June-1997% Copyright (c) 1996-1997 by Chenyang Xu and Jerry L. Prince %%  Image input/output%    rawread       - Read a Portable Bitmap file, or a raw file%    rawwrite      - Write a Portable Bitmap file, or a raw file% %  Image Display%    imdisp        - Display an image% %  Active Contour%    snakeinit     - Initialize the snake manually%    snakedeform   - Deform snake in the given external force field%    snakedeform2  - Deform snake in the given external force field with%                    pressure force%    snakedisp     - Display a snake%    snakeinterp   - Interpolate the snake adaptively%    snakeinterp1  - Interpolate the snake at a fixed resolution%                    (better implemented than snakeinterp)% %  Gradient Vector Flow%    GVF           - Compute the gradient vector flow field% %  Other%    dt            - Simple distance transform%    gaussianBlur  - Blurring an image using gaussian kernel   %    gaussianMask  - Generate a discrete gaussian mask

## 四、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社，2020.

[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社，2013.

[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社，2013.

[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社，2015.