I have a raster containing 0 and 1 as a numpy array, all pixels with a 1 are connected forming a line. This line is 1 pixel thick at all places. Using a pathfinding algorithm I have a list of the coordinates of all points (column, row), including the start and end point. The shape of my line is a squared U/rectangle missing the top part.
I want to find the points where the direction of the line changes for a longer stretch. For example from going down to going to the right, or from going to the right to going up.
I have looked at Finding the point of a slope change as a free parameter- Python; however since I my points are all either connected horizontally, vertically or diagonally this does not work. Also my u-shape can be diagonally in the array, therefore I am looking for the point where the type of connectivity changes for more than 2 pixel. Below is an example of my data, I would like to find (5,3)/(6,4) and (6,7)/(5,8)
a = np.array([[0,0,1,0,0,0,0,0,1],
[0,0,1,0,0,0,0,0,1],
[0,0,0,1,0,0,0,0,1],
[0,0,0,1,0,0,0,1,0],
[0,0,0,1,0,0,0,0,1],
[0,0,0,1,0,0,0,0,1],
[0,0,0,0,1,1,1,1,0],
[0,0,0,0,0,0,0,0,0]])
list_of_points = [(0,2),(1,2),(2,3),(3,3),(4,3),(5,3),(6,4),(6,5),(6,6),(6,7),(5,8),(4,8),(3,7),(2,8),(1,8),(0,8)]