Dear Python community,
I have Data in an X Y shape in a List.
xy = [[962, 656], [960, 492], [630, 658], [714, 656], [794, 742], [794, 576], [880, 656], [962, 574], [712, 740], [630, 490], [878, 492], [712, 824], [962, 740], [798, 824], [630, 742], [878, 572], [796, 490], [960, 822], [878, 740], [630, 574], [796, 656], [630, 824], [712, 492], [876, 824], [712, 574]]
Image/Plot of the Data:
I would like to sort the Data because they will be measured in random order. The point in the upper left-hand corner should be always in the first or last position in the end.
I Found a Stackoverflow post about it. How to sort a list of x-y coordinates
It helped. Now my question I would like to sort the Data with a Delta so that means for example 712 and 714 are in the same Group (treated as equal). That means I want them in the same Row(or Colum). The measurements are a bit noisy. The xy Positions are Position in an Image. I will analyze multiple Images. The sorting for the Objekts should be in the same order each time. The Upper left-Hand corner should be number one(852, 490). When the next dataPoint is like 740, 492 the sorting Algorithms won´t sort it in the same row (because 490 and 492 are different). That is my problem. This is why I thought about a delta... But maybe one of you will find a smarter solution..
# code from other post
new_xy = sorted(xy , key=lambda k: [(k[0]), (k[1])])
# something like
delta = +/- 5
new_xy = sorted(xy , key=lambda k: [(k[0] + delta), (k[1] + delta)])
Any help would be appreciated.
Thank you very much :)