Hannes Kuchelmeister
commited on
Commit
•
072e991
1
Parent(s):
44bd742
add variable to decide root of imag efilepaths and move export to outfolder instead of root dir
Browse files
annotation-preprocessing/0_fetch_from_database.py
CHANGED
@@ -84,6 +84,6 @@ if __name__ == "__main__":
|
|
84 |
'uuid', 'study_id', 'pos_z', 'focus_value', 'add_date']
|
85 |
|
86 |
print("Writing objects to file...")
|
87 |
-
df_objects.to_csv("objects.csv")
|
88 |
print("Writing stacks to file...")
|
89 |
-
df_stacks.to_csv("stacks.csv")
|
|
|
84 |
'uuid', 'study_id', 'pos_z', 'focus_value', 'add_date']
|
85 |
|
86 |
print("Writing objects to file...")
|
87 |
+
df_objects.to_csv("out/objects.csv")
|
88 |
print("Writing stacks to file...")
|
89 |
+
df_stacks.to_csv("out/stacks.csv")
|
annotation-preprocessing/1_splitting_into_patches.py
CHANGED
@@ -35,7 +35,7 @@ def get_neighbours(img, x, y, dimensions):
|
|
35 |
neighbours.append(None)
|
36 |
return neighbours
|
37 |
|
38 |
-
def extract_object_tiles(obj, stack_images):
|
39 |
x_start = int(obj.x_min / size) * size
|
40 |
x_end = int(math.ceil(obj.x_max / size)) * size
|
41 |
y_start = int(obj.y_min / size) * size
|
@@ -43,7 +43,7 @@ def extract_object_tiles(obj, stack_images):
|
|
43 |
|
44 |
tiles = []
|
45 |
|
46 |
-
focus_stack_images = list(map(lambda x: (x, Image.open(x.file_path)), stack_images))
|
47 |
|
48 |
# Get tiles of the image that contain bounding box of object
|
49 |
for y in range(y_start, y_end, size):
|
@@ -72,8 +72,8 @@ def save_tile(original_file_path, out_dir, x : int, y : int, img, overwrite = Fa
|
|
72 |
img.save(save_to)
|
73 |
return save_to
|
74 |
|
75 |
-
def save_obj_tiles(obj, out_folder, stack_images):
|
76 |
-
extracted = extract_object_tiles(obj, stack_images)
|
77 |
z_stacks = []
|
78 |
for z_stack in extracted:
|
79 |
z_stack_images = []
|
@@ -106,10 +106,10 @@ def save_obj_tiles(obj, out_folder, stack_images):
|
|
106 |
|
107 |
return z_stacks
|
108 |
|
109 |
-
def save_stack(stack, out_folder):
|
110 |
z_stacks = []
|
111 |
for obj in stack.objects:
|
112 |
-
z_stacks.extend(save_obj_tiles(obj, out_folder, stack.images))
|
113 |
return z_stacks
|
114 |
|
115 |
|
@@ -117,10 +117,14 @@ if __name__ == "__main__":
|
|
117 |
load_dotenv()
|
118 |
print("Geting environment variables...")
|
119 |
size = int(os.getenv('IMG_SIZE'))
|
|
|
|
|
|
|
|
|
120 |
|
121 |
print("Loading data from csv files...")
|
122 |
-
objects = pd.read_csv("test_objects.csv", index_col=0)
|
123 |
-
stacks = pd.read_csv("test_stacks.csv", index_col=0)
|
124 |
|
125 |
|
126 |
stacks_dict = defaultdict(lambda: StackEntry())
|
@@ -142,7 +146,7 @@ if __name__ == "__main__":
|
|
142 |
|
143 |
print("Generating image tiles and writing them to file...")
|
144 |
for stack in stacks_dict.values():
|
145 |
-
z_stacks.extend(save_stack(stack,""))
|
146 |
|
147 |
# randomize z_stacks
|
148 |
print("Shuffling data...")
|
|
|
35 |
neighbours.append(None)
|
36 |
return neighbours
|
37 |
|
38 |
+
def extract_object_tiles(obj, stack_images, in_folder):
|
39 |
x_start = int(obj.x_min / size) * size
|
40 |
x_end = int(math.ceil(obj.x_max / size)) * size
|
41 |
y_start = int(obj.y_min / size) * size
|
|
|
43 |
|
44 |
tiles = []
|
45 |
|
46 |
+
focus_stack_images = list(map(lambda x: (x, Image.open(os.path.join(in_folder, x.file_path))), stack_images))
|
47 |
|
48 |
# Get tiles of the image that contain bounding box of object
|
49 |
for y in range(y_start, y_end, size):
|
|
|
72 |
img.save(save_to)
|
73 |
return save_to
|
74 |
|
75 |
+
def save_obj_tiles(obj, out_folder, in_folder, stack_images):
|
76 |
+
extracted = extract_object_tiles(obj, stack_images, in_folder)
|
77 |
z_stacks = []
|
78 |
for z_stack in extracted:
|
79 |
z_stack_images = []
|
|
|
106 |
|
107 |
return z_stacks
|
108 |
|
109 |
+
def save_stack(stack, out_folder, in_folder):
|
110 |
z_stacks = []
|
111 |
for obj in stack.objects:
|
112 |
+
z_stacks.extend(save_obj_tiles(obj, out_folder, in_folder, stack.images))
|
113 |
return z_stacks
|
114 |
|
115 |
|
|
|
117 |
load_dotenv()
|
118 |
print("Geting environment variables...")
|
119 |
size = int(os.getenv('IMG_SIZE'))
|
120 |
+
root_in = os.getenv('ROOT_IN')
|
121 |
+
|
122 |
+
print(f'img_size: ')
|
123 |
+
print(f'in_folder: {root_in}')
|
124 |
|
125 |
print("Loading data from csv files...")
|
126 |
+
objects = pd.read_csv("out/test_objects.csv", index_col=0)
|
127 |
+
stacks = pd.read_csv("out/test_stacks.csv", index_col=0)
|
128 |
|
129 |
|
130 |
stacks_dict = defaultdict(lambda: StackEntry())
|
|
|
146 |
|
147 |
print("Generating image tiles and writing them to file...")
|
148 |
for stack in stacks_dict.values():
|
149 |
+
z_stacks.extend(save_stack(stack,"out", root_in))
|
150 |
|
151 |
# randomize z_stacks
|
152 |
print("Shuffling data...")
|