Say I have the following array/matrix in python (any language will do, to be honest). A =
[0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 1 1 1 1 1 0 0 0 0
0 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0]
Is there any easy way to manipulate entries in this array as if they are pixels. Example, would there be any way to create an interior and a surface of arbitrary length, to get, for example:
[0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0
0 1 1 0 0 1 0 0 0 0
0 1 1 0 0 0 1 0 0 0
0 0 1 0 0 0 1 1 0 0
0 0 1 0 0 0 1 0 0 0
0 0 1 1 0 1 1 0 0 0
0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0]
Perhaps there is some way to recursively solve this, or maybe in a different way, which would rely on the entries around each element. Any thoughts?
You can just check the value and the direct neighborhood of every pixel: Your resulting image is 1 where:
It is 0 everywhere else. The image below might help to illustrate what I mean:
Test these conditions for each array entry. Just be careful at the boundaries.
If you have access to an image processing library there is another approach you can take: create a copy of your image, errode it by one pixel and subtract it from the original.