I am trying to do an analysis of the shape of an object in an image in MATLAB (in particular). For this, I found boundary pixels. For each border pixel, I compute it in the neighborhood using the 8-neighborhood theory. Now I calculate the tangent of the point to its only neighborhood (it depends on how I choose clockwise or in another way). My algorithm works fine if each pixel has exactly two neighbors. For the figures shown in this image (about 9 X 15 pixels).
But if there are more than two pixel neighbors, then my algorithm gets confused. For example, as shown in (order of 9 X 15 pixels).

I want to take the tangent of each border pixel with its neighboring pixel clockwise or counterclockwise, and if you notice a second image that is a valid border image, if I move clockwise, then the red pixel neighbor will be green and the green neighbor will be green the clockwise will be “1” and the neighbor “1” is “2”, but then I cannot go back to the blue and brown pixels, and I cannot visit and take the tangent of each border pixel with its neighboring pixel.
I studied the graph of node visiting algorithms in which you support a queue or stack, but then in this case I not only want to visit every pixel, but also take tangents to each pixel only with the right neighboring pixel in which direction I move.
This is an example of a problem, and similar problems may occur in some other way, so I'm trying to create a general algorithm for it. I would be grateful for your help. Thanks.
source share