Hannes Kuchelmeister commited on
Commit
3e2d18e
1 Parent(s): ac6b398

add script to convert annotations to csv

Browse files
data-preprocessing/extract_annotations.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from itertools import chain
4
+ from dotenv import load_dotenv
5
+ import pandas as pd
6
+
7
+ def to_relative_focus(stack):
8
+ best_index = stack["best_index"]
9
+ images = stack["images"]
10
+
11
+ best_value = images[best_index]["focus_value"]
12
+ for i in range(len(images)):
13
+ images[i]["focus_value"] = images[i]["focus_value"] - best_value
14
+ return stack
15
+
16
+
17
+ def flatten_stack(stack):
18
+ images = stack["images"]
19
+
20
+ def f(image):
21
+ del image["neighbours"]
22
+ image["stack_id"] = stack["stack_id"]
23
+ image["obj_name"] = stack["obj_name"]
24
+ return image
25
+
26
+ images = list(map(f, images))
27
+ return images
28
+
29
+
30
+ if __name__ == "__main__":
31
+ load_dotenv()
32
+ data_file = os.getenv('DATA_FILE')
33
+ out_file = os.getenv('OUT_FILE')
34
+
35
+ with open(data_file) as f:
36
+ content = json.load(f)
37
+
38
+ annotated = filter(lambda x: x["best_index"], content)
39
+ relative_focus = map(to_relative_focus, annotated)
40
+ flattened = chain(*map(flatten_stack,relative_focus))
41
+
42
+ dataframe = pd.DataFrame(flattened)
43
+ dataframe.to_csv(out_file)
44
+
45
+
data-preprocessing/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-dotenv