0

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!

Jules
  • 7
  • 5
  • what is in `measurements`? how can `clmn(measurements, 3)==1` ever be true since it returns a list? what is `section_1.append([xy])` supposed to do? what is `measurements[:,1]`? – depperm Jun 19 '17 at 17:37
  • Edited the question, but still horribly stuck! – Jules Jun 20 '17 at 09:28
  • 1
    Your description leaves too much open; try writing a self-contained piece of (pseudo) code that expresses your intent, that is usually more precise than natural language. – Eelco Hoogendoorn Jun 20 '17 at 14:59
  • Updated it with a segment I am working on now; thank you so much in advance! – Jules Jun 20 '17 at 15:35

0 Answers0