I. Introduction to GVF Snake algorithm

In the process of segmentation, the contour curve of the image should be as smooth as possible. However, the Snake model makes the contour smoother without depression and is more sensitive to the selection of initial position, which greatly increases the uncertainty of the model. GVF Snake model extends the gradient force to the entire image. On the one hand, it increases the dynamic capture ability of contour curves, and on the other hand, it overcomes the defect that contour lines in Snake model cannot be depressed. GVF Snake model has a wide range of external forces and has the characteristics of bidirectional driving contour motion. For an image, boundary detection operator is first used to obtain f(x, y), w(x, y) =[u(x, y), V (x, y)] of the image I(x, y) as the external force of the model, then the energy functional of GVF Snake model can be expressed asThe partial differential equation of the gradient force field U and v functions with respect to time T in GVF can be expressed as

Part of the source code

clc; clear all; close all;
rand('state'.0);
warning off all;
path([pwd '\\toolbox'], path);
filename = 'chest'; % Name of image to be processed % load image [I,map] = rawread(sprintf('images\\%s.pgm', filename)); % Calculate the edge image f =1 - I/255; % GVF processing [u,v] = GVF(f,0.1.80); % formalized processing mag =sqrt(u.*u+v.*v);
px = u./(mag+1e-10); py = v./(mag+1e-10); % display result figure(1);
subplot(1.2.1); imdisp(I); title('Original image'.'FontWeight'.'Bold');
subplot(1.2.2); imdisp(f); title('Edge image'.'FontWeight'.'Bold'); % initial edge curve 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 iteration 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(['Iterative process, the number of iterations is =' num2str(i*5)].'FontWeight'.'Bold')
    pause(0.2);
end
title('GVF Snake Edge Extraction Mark '.'FontWeight'.'Bold')
mag = sqrt(u.*u+v.*v);
px = u./(mag+1e-10); py = v./(mag+1e-10); % display result figure(1);
subplot(1.2.1); imdisp(I); title('Original image'.'FontWeight'.'Bold');
subplot(1.2.2); imdisp(f); title('Edge image'.'FontWeight'.'Bold'); % initial edge curve 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, ora 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


Copy the code

Third, the operation result

Iv. Matlab version and references

1 Matlab version 2014A

2 References [1] CAI Limei. MATLAB Image Processing — Theory, Algorithm and Case Analysis [M]. Tsinghua University Press, 2020. [2] Yang Dan, ZHAO Haibin, LONG Zhe. Detailed Analysis of MATLAB Image Processing Examples [M]. Tsinghua University Press, 2013. [3] Zhou Pin. MATLAB Image Processing and Graphic User Interface Design [M]. Tsinghua University Press, 2013. [4] LIU Chenglong. Proficient in MATLAB image processing [M]. Tsinghua University Press, 2015.