-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhd2mojo.py
executable file
·41 lines (33 loc) · 1.05 KB
/
hd2mojo.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
#!/usr/bin/python
import os
import h5py
import glob
import argparse
import numpy as np
from toMojo.np2imgo import Imgo
from toMojo.np2sego import Sego
help = {
'out': 'output mojo parent (default mojo)',
'hd2mojo': 'Expand a hd5 File into a mojo folder!',
'hd5': 'input hd5 file (default hd5)',
}
paths = {}
parser = argparse.ArgumentParser(description=help['hd2mojo'])
parser.add_argument('hd5', default='hd5', nargs='?', help=help['hd5'])
parser.add_argument('out', default='mojo', nargs='?', help=help['out'])
# attain all arguments
args = vars(parser.parse_args())
for key in ['hd5', 'out']:
paths[key] = os.path.realpath(os.path.expanduser(args[key]))
# Add each png file as a slice
with h5py.File(paths['hd5'],'r') as hi:
group = hi[hi.keys()[0]]
shape = group.shape
dtype = group.dtype
outfile = Imgo(paths['out'])
if dtype is not np.uint8:
outfile = Sego(paths['out'])
for zi in range(shape[0]):
outfile.run(group[zi, :, :], zi)
# Write as image or segmentation
outfile.save(shape)