-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtilerize_neontree.py
50 lines (40 loc) · 1.74 KB
/
tilerize_neontree.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
47
48
49
50
import os
import sys
from pathlib import Path
# Allow loading tilerizer from the above hierarchy
higher_level_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(higher_level_folder)
from tilerizer import Tilerizer
def tile_training(tile_path, annot_path):
tif_file_paths = tile_path.glob("*.tif")
for tif_file_path in tif_file_paths:
file_name = tif_file_path.stem
annot_file_name = file_name + ".xml"
annot_file_path = annot_path / annot_file_name
print("Starting tiling TIF: {}".format(file_name))
tilerizer = Tilerizer(tif_file_path, annot_file_path)
tilerizer.create_tiles()
def tile_evaluation(tile_path, annot_path):
tif_file_paths = tile_path.glob("*.tif")
for tif_file_path in tif_file_paths:
file_name = tif_file_path.stem
annot_file_name = file_name + ".xml"
annot_file_path = annot_path / annot_file_name
if annot_file_path.exists():
print("Starting tiling TIF: {}".format(file_name))
tilerizer = Tilerizer(tif_file_path, annot_file_path)
tilerizer.create_tiles()
else:
print("Following TIF file has no annotation: {}".format(file_name))
def main():
# Please modify the folder_path to the NeonTree official dataset
# folder_path = "path/to/dataset"
folder_path = "/network/scratch/a/arthur.ouaknine/data/NeonTree"
neontree_path = Path(folder_path)
annot_path = neontree_path / "annotations"
evaluation_rgb_path = neontree_path / "evaluation" / "RGB"
training_rgb_path = neontree_path / "training" / "RGB"
tile_training(training_rgb_path, annot_path)
tile_evaluation(evaluation_rgb_path, annot_path)
if __name__ == "__main__":
main()