Finding the best neighboring pixel

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).

enter image description here

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.

+5
source share
1 answer

As btilly already said. The solution is to find the borders between the pixels, not the pixels themselves. I recommend you part of the potrace algorithm. This is an algorithm for vectorizing binary images. An interesting part for you is decompiling the Path. Here is the idea of ​​decompiling the path:

Path following

Potrace algorithm you can find here.

Another algorithm is from William Burger and Burger in the book "Digital Image Processing Using Algorithmic Introduction Using the Link Description Here" . In the link you can see part of the book. The moveable part is the “TraceContour” function on page 538. This algorithm works the way you thought and walk around the “internal” pixels. I found some explanation of Alorith here , with internal border tracing. You can execute an Algorithm with four or eight adjacent connections.

The connectivity

+1
source

Source: https://habr.com/ru/post/1209800/


All Articles