forked from damaggu/cellSAM_devel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize.py
46 lines (34 loc) · 1.52 KB
/
resize.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
import matplotlib.pyplot as plt
files = "/home/markus/PycharmProjects/cellSAM_devel/results_hidden_256_100_100_tuning_tryCatch_2/inferences/"
save_path = "/home/markus/PycharmProjects/cellSAM_devel/results_hidden_256_100_100_tuning_tryCatch_2/inferences_reshaped/"
save_path_png = "/home/markus/PycharmProjects/cellSAM_devel/results_hidden_256_100_100_tuning_tryCatch_2/inferences_reshaped_png/"
import os
import imageio.v3 as iio
if not os.path.exists(save_path):
os.makedirs(save_path)
if not os.path.exists(save_path_png):
os.makedirs(save_path_png)
all_files = os.listdir(files)
for file in all_files:
labels = iio.imread(files + file)
# gt_path = "/home/markus/PycharmProjects/cellSAM_devel/neurips_tuning/Tuning/images/" + file.split('.')[0]
gt_path = "/home/markus/PycharmProjects/cellSAM_devel/neurips_hidden/Testing/Hidden/images/" + file.split('.')[0]
endings = ['.tif', '.tiff', '.png', '.bmp']
for end in endings:
if os.path.exists(gt_path + end):
gt_path = gt_path + end
break
gt_mask = iio.imread(gt_path)
if gt_mask.shape[0] < 512:
# remove padding
padding = 512 - gt_mask.shape[0]
labels = labels[padding // 2:-padding // 2, :]
if gt_mask.shape[1] < 512:
padding = 512 - gt_mask.shape[1]
labels = labels[:, padding // 2:-padding // 2]
iio.imwrite(save_path + file, labels)
# save as png
plt.imshow(labels)
plt.title(file)
plt.savefig(save_path_png + file.split('.')[0] + '.png')
plt.close()