isband.m

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

M
40
字号
function band = isband( phi, front, width )
% CALCBAND Determine which points are within narrow band
%    CALCBAND( phi, front, width ) Based on the indices of the
%    front points, determine which pixels of phi are within a
%    narrow band of width 'width' of the front points. Return a
%    boolean matrix the same size as phi.


% grab size of phi
[ m, n ] = size( phi );

% precompute width squared to save computations later
widthsq = width^2;

% retrieve indices of and total number of front points
n_front = size( front, 1 );

% create an boolean matrix whose value at each pixel is 0 or 1
% depending on whether that pixel is a band point or not
band = zeros( m, n );

% for each pixel in phi
for ii = 1 : m;
  for jj = 1 : n;

    % check if it is within 'width' of a front pixel
    closest_dist = inf;
    for k = 1 : n_front;

      dist = sum( ( front( k, : ) - [ ii, jj ] ).^2 );
      if( dist < widthsq )
	band( ii, jj ) = 1;
	break;
      end;

    end;

  end;
end;

⌨️ 快捷键说明

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