MATLAB:像波前算法一样制作矩阵

MATLAB: Making matrix like in Wavefront algorithm

我有这种矩阵 (13 x 13):

0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   0   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0

我能否以某种方式在每次迭代中将中心零和构成 "walls" 的零周围的值增加一并使其成为这样?

0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   1   2   2   2   2   2   2   2   2   2   1   0
0   1   2   3   3   3   3   3   3   3   2   1   0
0   1   2   3   2   2   2   2   2   3   2   1   0
0   1   2   3   2   1   1   1   2   3   2   1   0
0   1   2   3   2   1   0   1   2   3   2   1   0
0   1   2   3   2   1   1   1   2   3   2   1   0
0   1   2   3   2   2   2   2   2   3   2   1   0
0   1   2   3   3   3   3   3   3   3   2   1   0
0   1   2   2   2   2   2   2   2   2   2   1   0
0   1   1   1   1   1   1   1   1   1   1   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0

如果你有图像处理工具箱,那就是单行本:

%# assume your matrix is called A
result = bwdist(~A,'cityblock')

'result'是如果你只能水平或垂直步进,A中每个非零像素到最近的零的距离。