initdist.m

来自「这是一个利用水平集方法进行分割的方法」· M 代码 · 共 38 行

M
38
字号
function newphi = initdist( phi, front )% INITDIST Reinitialize to signed distance function%    INITDIST( phi, front ) Reinitializes all points in phi to the%    signed distance of the point to the front.% grab the size of phi[ m, n ] = size( phi );% grab the total number of front pointsn_front = size( front, 1 );% fill the new phi function with zeros to startnewphi = zeros( size( phi ) );% if there are no front points then returnif( n_front == 0 )  return;end% for every pixelfor i = 2 : m - 1;  for j = 2 : n - 1;    % find the front pixel it is closest to    closest_dist = inf;    for k = 1 : n_front;      dist = sum( ( front( k, : ) - [ i, j ] ).^2 );      if( dist < closest_dist )	closest_dist = dist;      end;    end;    % and reinitialize the distance    newphi( i, j ) = sign( phi( i, j ) ) * ceil( sqrt( closest_dist ) );  end;end;

⌨️ 快捷键说明

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