-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain2index.py
31 lines (25 loc) · 1003 Bytes
/
domain2index.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
import numpy as np
import os
import sys
import nrrd
if (len(sys.argv) < 3):
print 'Error: missing arguments!'
print 'e.g. python domain2index.py indexoutput.nrrd domainprefix(000#)'
else:
print 'Adding to index', str(sys.argv[1]), '....'
for x in range(2,(len(sys.argv))):
for i in range(1,255):
fn = str(sys.argv[x]) + str(i).zfill(4) + '.nrrd'
if os.path.exists(fn):
print 'adding data from file', fn
readdata, option = nrrd.read(fn)
readdata[readdata>0] = np.uint8(i)
print 'appending index', str(i)
indfile = str(sys.argv[1])
if os.path.exists(indfile):
domain, option = nrrd.read(indfile)
else:
domain = np.zeros(readdata.shape,np.uint8)
domain[readdata==np.uint8(i)]=np.uint8(i)
nrrd.write(indfile, domain, options=option)
print 'Done.'