⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initdist.m

📁 matlab 代码为图像的分割
💻 M
字号:
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 points
n_front = size( front, 1 );

% fill the new phi function with zeros to start
newphi = zeros( size( phi ) );

% if there are no front points then return
if( n_front == 0 )
  return;
end

% for every pixel
for 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -