brianthelion

blob_me.py

Dec 5th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. def blob_me(listofcoords,distance) :
  2.     blobs = {}
  3.     centroids = {}
  4.     blob_count = 0
  5.     for coord in listofcoords :
  6.         found_match = None
  7.         for k in blobs.keys() :
  8.             if distance_between(coord,centroids[k]) <= distance :
  9.                 found_match = k
  10.                 break
  11.         if found_match is None :
  12.             blobs[blob_count] = [ coord ]
  13.             centroids[blob_count] = [ coord ]
  14.             blob_count += 1
  15.         else :
  16.             blobs[found_match].append(coord)
  17.             centroids[found_match] = calculate_centroid( blobs[found_match] )
  18.     return blobs.values()
Advertisement
Add Comment
Please, Sign In to add comment