I need to sort an array of circles (as result of HoughCircles function) by top to bottom and left to right but I can't manage to do so.
I used the python built-in sorted method as follows:
circles = np.round(circles[0, :]).astype("int")
circles = sorted(circles, key=lambda v: [v[0], v[1]])
And I get the following result: image
For instance, in this example image it jumps from circle 61 to 64, from 96 to 100 and so on.
It wrongly sorted some circles, and it seems that it's because some circles are a pixel or two misaligned, causing these mistakes.
EDIT:
These are my raw data and sample image:
raw data of circles [[y, x, radius]]
