-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMost_dist_pix.py
48 lines (43 loc) · 1.58 KB
/
Most_dist_pix.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
import os
import sys
import glob
import math
import csv
work_dir = sys.argv[1:]
for sub_dir in work_dir:
print('Processing: '+sub_dir)
os.chdir(sub_dir)
files = glob.glob('*.txt')
files.sort()
max_dist_master = [] #a matrix with maximum distances from all files
for file in files:
max_dist_list = [] #a list of maximum distances in a file timeframes
max_dist_list.append(file[:-4])
coor_list = [[]] #a list with all pixels coordinates in a file
frame = 0
with open(file) as f:
for line in f:
line = list(map(int, line.split("\t")))
if line[2] > frame: #3rd number in line = number of frame
frame += 1
coor_list.append([])
coor_list[frame].append(line)
for coor_frame in coor_list:
max_distance = 0
for i in range(len(coor_frame)-1):
for j in range(i+1,len(coor_frame)):
a = coor_frame[i][0:2]
b = coor_frame[j][0:2]
distance=math.dist(a, b)
if(distance>max_distance):
max_distance = distance
max_dist_list.append(max_distance)
max_dist_master.append(max_dist_list)
#transpose (make rows into columns)
max_dist_master = list(zip(*max_dist_master))
#save into csv
result_file = sub_dir.split("/")[-1] + ".csv"
os.chdir("..")
with open(result_file, "w+", newline="") as f:
writer = csv.writer(f)
writer.writerows(max_dist_master)