levelsetorig.m

来自「matlab 代码为图像的分割」· M 代码 · 共 54 行

M
54
字号
function phi = levelsetorig( im, center, radius, isinside, d_it, m_it, m_name )
% LEVELSETORIG Segment the image
%    LEVELSETORIG( im, center, radius, isinside, d_it, m_it, m_name )
%    Segment the image im using level sets, given that the
%    zero-level, level-set is a circle with the argument center and
%    radius. The current segmented image is displayed every d_it
%    iterations and written to disk every m_iterations with name
%    m_name*.png.

% constants
ITERATIONS = 10000;
delta_t  = 0.0005;

% initialize the phi function
phi = initphi( size( im ), center, radius, isinside );

% calculate the stopping function
K_I = edgestop( im, 5, 3.25 );

for ii = 1 : ITERATIONS;

  % display current iteration
  fprintf( 1, '%d\n', ii );

  % display the segmented image every 'd_it' iterations
  if( mod( ii - 1, d_it ) == 0 )
    disp( 'Displaying Segmented Image' );
    segim = createimage( im, phi );
    clf; imshow( segim );
    drawnow;
  end;

  % write current segmented image to file every 'm_it'
  % iterations
  if( mod( ii - 1, m_it ) == 0 )
    segim = createimage( im, phi );
    filename = strcat( m_name, sprintf( '%06d', ( ( ii - 1 )/ m_it ) + 1 ), '.png' );
    imwrite( segim, filename );
  end;

  % determine the indices of the front points
  [ x, y ] = find( isfront( phi ) );
  front = [ x, y ];

  % calculate the speed at those points and then globally extend
  % the speed to all the other points
  speed = calcspeed( phi, K_I, front );
  speed = extendspeed( speed, front );

  % update phi
  phi = phi - delta_t * speed;

end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?