C # Alternative quick methods to get boundary coordinates of an irregular object?

Currently, I have a problem finding a good algorithm for obtaining the coordinates of each external boundary point of an object, which, unfortunately, can be complex and contain internal areas.


enter image description here

I have a list of points containing each pixel point of an object already created from the marking algorithm of the connected component. This allowed me to check every coordinate around each pixel in the image, and if it is not there, then I know its space or edge through the following.

public List<IntPoint> SquareSearch(List<IntPoint> ListOfPoints, IntPoint point) { List<IntPoint> UnfoundPixels = new List<IntPoint>(); int MoveX = point.X; int MoveY = point.Y; for (int LTR = MoveX - 1; LTR <= MoveX + 1; LTR++) { for (int TTB = MoveY - 1; TTB <= MoveY + 1; TTB++) { if (ListOfPoints.IndexOf(new IntPoint(LTR, TTB)) == -1) { if ((LTR > -1) && (TTB > -1)) { UnfoundPixels.Add(new IntPoint(LTR, TTB)); } } } } } 

However, this process is very slow and proportional to the size of each object, since it must be repeated for each pixel in the object. Any suggestions on an alternative method?

+4
source share
3 answers

Well, the solution was a combination of the above answers to really speed it up, not only did I need a new algorithm, but I had to use hashes for ... I went with Theo Pavlidis algorithm

http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/contour_tracing_Abeer_George_Ghuneim/theo.html

Unfortunately, the algorithm alone could not beat the elemental approach using hash sets, however, the inclusion of hash sets in the algorithm led to a 62% increase in speed. This is also not a complicated application method, so I only included the page above.

Greetings to all who helped.

+1
source

I would try to make some kind of edge detection algorithm.

Say you go down from the top in the middle of the image until you click the edge, then you can follow that edge by scanning 8 pixels and you will work around an object like this. At each position, you check whether your current coordinates are outside the bounding box and increase as necessary.

+2
source

One of the performance improvements is to use a HashSet<T> instead of a List<T> . This will greatly speed up the verification.

+1
source

All Articles