-
Notifications
You must be signed in to change notification settings - Fork 0
/
beadtracker.py
55 lines (42 loc) · 1.33 KB
/
beadtracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import beadfinder
delta = 0
def detect_displacement(beads1, beads2):
'''
calculate the displacement of each blob between two frames
'''
global delta
for i in range(len(beads1)):
min_distance = delta+1
# find minimum distance between the
# beads[i] and one of the beads2
for j in range(len(beads2)):
#calculate distance
d = beads1[i].distanceTo(beads2[j])
if d < min_distance and d <= delta:
min_distance = d
# print min_distance only when the blob
# moves less than the delta
if min_distance != delta+1:
print("{:.4f}".format(min_distance))
def main():
global delta
'''
get min_pixels, tau, delta, filenames ...
from the standard input and trace beads movements
'''
# get data from stdin
min_pixels = int(sys.argv[1])
tau = float(sys.argv[2])
delta = float(sys.argv[3])
files = sys.argv[4:]
# find beads in the pictures
blobs = []
for f in files:
bf = beadfinder.BeadFinder(f, tau)
blobs.append(bf.getBeads(min_pixels))
# pass each to continues frame to detect_displacement function
for i in range(len(blobs)-1):
detect_displacement(blobs[i], blobs[i+1])
if __name__ == "__main__":
main()