Starting with a 2d array of 0s and 1s, I need to identify which 1s form a united fence completely enclosing one or more adjacent 0s. Those 0s are considered adjacent if they touch on their sides or the diagonal. The fence must exist on the neighboring diagonal as well.
This is the 2d array, and what I want are the 1s which indicate the fence, and then everything else should be zero. This is a simple case, in reality the array is a png image, and I want all the fences that may exist in it.
Is ndimage the module needed? Any advice please.
array=
[[1,1,1,1,1,1],
[1,1,0,0,1,1],
[1,1,0,1,1,1],
[1,1,1,1,1,1],
[0,0,1,1,0,0]]
answer=
[[0,1,1,1,1,0],
[0,1,0,0,1,0],
[0,1,0,1,1,0],
[0,1,1,1,0,0],
[0,0,0,0,0,0]]