extendspeed.m
来自「matlab 代码为图像的分割」· M 代码 · 共 32 行
M
32 行
function speed = extendspeed( speed, front )
% EXTENDSPEED Extends speed to non-front points
% EXTENDSPEED( speed, front ) Extends speed function to
% all pixels in 'speed'. For each non-front pixel, its speed is
% the same as the speed of the closest front pixel.
% grab the size of the speed matrix
[ m, n ] = size( speed );
% grab the total number of front points
n_front = size( front, 1 );
% for every pixel
for i = 1 : m;
for j = 1 : n;
% find the front pixel it is closest to
closest_dist = inf;
closest_pt = front( 1, : );
for k = 1 : n_front;
dist = sum( ( front( k, : ) - [ i, j ] ).^2 );
if( dist < closest_dist )
closest_dist = dist;
closest_pt = front( k, : );
end;
end;
% and copy its speed
speed( i, j ) = speed( closest_pt( 1 ), closest_pt( 2 ) );
end;
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?