forked from digitalpathologybern/hover_next_train
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_pannuke_to_conic.py
More file actions
36 lines (33 loc) · 1.17 KB
/
convert_pannuke_to_conic.py
File metadata and controls
36 lines (33 loc) · 1.17 KB
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
import os
import argparse
import numpy as np
from scipy.ndimage import label
# quick and dirty script to convert pannuke masks to lizard/conic format
# define path_to_pannuke to point to the folder containing the pannuke masks
# the folder should contain 3 subfolders: fold1, fold2, fold3 with the respective masks.npy files
# the script will create a labels.npy file in each of the 3 subfolders
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--path",
type=str,
default="pannuke/masks",
help="specify the path to the pannuke masks folder",
)
path_to_pannuke = parser.parse_args().path
for f in ["fold1", "fold2", "fold3"]:
y = np.load(f"{path_to_pannuke}/{f}/masks.npy")
y_inst = np.stack(
[label(y_)[0] for y_ in np.sum(y[..., :-1], axis=-1).astype(int)]
)
y_cls = np.max((y[..., :-1] > 0) * np.arange(1, 6), axis=-1)
y_lab = np.stack([y_inst, y_cls], axis=-1)
np.save(
os.path.join(
path_to_pannuke,
f,
"labels.npy",
),
y_lab,
)
print("done")