-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeNRRDs.py
43 lines (40 loc) · 1.24 KB
/
mergeNRRDs.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
import numpy as np
import sys, os
import nrrd
if (len(sys.argv) < 2):
print('Error: missing arguments!')
print('e.g. python mergeNRRDs.py imageOut.nrrd imageIn1.nrrd [ImageIn#.nrrd...]')
else:
Iout = str(sys.argv[1])
brightest = 0
level = 255;
bright = ""
errorOn = ""
dataMax = 0
dataBk = 0
result = []
for i in range(2,len(sys.argv)):
dataBk = np.copy(result)
Iin = str(sys.argv[i])
print('Processing %s...'% (Iin))
data, header = nrrd.read(Iin)
sh = np.shape(data)
if (dataMax < np.max(data)):
dataMax = np.max(data)
if (dataMax > 255):
scale = dataMax/255
print("Scalling (" + str(scale) + ")...")
data = np.uint8(data/scale)
data[data > 255] = np.uint8(255)
if (i == 2):
result = np.uint8(data)
shTest = sh
brightest = np.sum(data)
else:
if (sh == shTest):
result = np.maximum(result, data, dtype=np.uint8)
else:
print('ERROR: %s not the same size!' + str(sh) + ' - ' + str(shTest))
normData = np.uint8(result)
nrrd.write(Iout, normData, header=header)
print('saved to ' + Iout)