MATLAB: creating a matrix, as in the Wavefront algorithm

I have such a matrix (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 

Can I somehow increase the values ​​around the center zero and the zeros that make the β€œwalls” one at a time in each iteration and do it like this?

 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 
+6
source share
1 answer

If you have an image processing toolbar, this is single-line:

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

'result' is the distance from each non-zero pixel to the nearest zero if you can only perform horizontal or vertical position.

+6
source

Source: https://habr.com/ru/post/983653/


All Articles