I am tracking multiple centroids of objects in one plane and have n different arrays of x,y coordinates of the centroid for every section (of n amounts of sections) I have.
I would like to find the nearest value in every array in x AND y (so: centroids that overlap most in the z-direction (that is: across the different sections). I found topics on the 'find nearest' through numpy, but I cannot figure out how to do this across arrays and group the resultant centroid overlap together in one array.
I did find scipy.spatial.distance.cdist, but I am not sure how to implement it here.
My measurements (np.arrays) look like the following:
section_1: [432,23],[23,235]...
section_2: [562,13],[71,575]...
etc.
This issue is very much related, but does not return an arrays for each pair of centroids: Euclidean distance between points in two different Numpy arrays, not within
I am a relative beginner in Python, so please be gentle on me. I know the below code won't work, but I am looking for something like this.
# CREATE SEPARATE ARRAYS FOR SECTIONS
s = {}
width = list(range(1,10000))
sections = np.unique(measurements[:, 3])
for x in sections:
mask = measurements[:, 3] == x
s[x] = measurements[mask, 1:3]
# FIND CLOSTEST COORDINATES THAT OVERLAP IN THOSE SECTIONS
def find_nearest_coordinate(centroids0, centroids1):
idx = np.array([np.linalg.norm(x+y) for (x,y) in object0-object1]).argmin()
return np.array[idx]
for i, x in enumerate(sections):
if x > max(sections) - 1:
break
find_object2 = find_nearest_coordinate(s[1], s[2])
This would eventually yield object_'' arrays for every object. It should contain all x.y coordinates in the z direction. Object0 should contain all centroids in one particular section, Object1 the centroids in the adjacent section.
Thanks so much!