I want to calculate the perimeter of a given structure of a numpy array. With perimeter, I mean the exact perimeter of the structure in the numpy array. The structure may include holes.
My current aproach looks something like this:
import numpy a = numpy.zeros((6,6), dtype=numpy.int) a[1:5, 1:5] = 1;a[3,3] = 0

As you can see, it displays all neighboring cells, but their sum is not equal to the perimeter of the patch. The hole in the example array is calculated as 1, although it correctly has 4 edges. There are similar problems with large holes of various shapes.
I asked similar questions in the past, but all the solutions provided that were somehow not resolved in the correct output values โโat the end. Does anyone have an idea how to do this? No other packages besides numpy, scipy and base packages, please.
source share