-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tile_segmentation.py
68 lines (48 loc) · 1.88 KB
/
run_tile_segmentation.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import sys
import glob
from deprecated import prepare_tiles_4seg as prep_4seg
from convnet.deprecated import unet_segmentation as useg
def get_dir_dic(root_dir):
dir_dic = {}
list_dirs = glob.glob(root_dir + '/*/')
for ldir in list_dirs:
if os.path.isdir(ldir):
if ldir.find('magick_tmp') != -1:
continue
# get mask tiles dir path
tiles_dir = os.path.join(ldir, 'heat_map/seg_tiles')
seg_dir = os.path.join(ldir, 'heat_map/TAU_seg_tiles')
tmp_dir = os.path.join(ldir, 'heat_map/hdf5_tiles')
if not os.path.exists(seg_dir):
os.mkdir(seg_dir)
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
dir_dic[tiles_dir] = (seg_dir,tmp_dir)
return dir_dic
def run_segmentation(root_dir,config_file):
dirs_dic = get_dir_dic(root_dir)
for di in dirs_dic.keys():
dirs = dirs_dic[di]
seg_dir = dirs[0]
hd5_dir = dirs[1]
print('Preparing tiles in {} for segmentation.'.format(di))
#export temporary hdf5 for segmentation
prep_4seg.run_prepare(di,hd5_dir,seg_dir,'tif')
print('**************')
print('** Beginning segmentation. It will take several minutes.')
print('**************')
#run convnet segmentation
useg.run_segmentation(hd5_dir,seg_dir,config_file)
status_file = os.path.join(seg_dir,'seg_complete.log')
with open(status_file, 'w+') as sfile:
sfile.write('1')
def main():
if len(sys.argv) != 3:
print('Usage: run_tile_segmentation <root_dir> <config_file>')
exit()
root_dir = str(sys.argv[1]) # abs path to where the images are
config_file = str(sys.argv[2]) # abs path to where the images are
run_segmentation(root_dir,config_file)
if __name__ == '__main__':
main()