-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddPadding.py
More file actions
executable file
·30 lines (25 loc) · 912 Bytes
/
addPadding.py
File metadata and controls
executable file
·30 lines (25 loc) · 912 Bytes
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
import numpy as np
import sys, os
import nrrd
if (len(sys.argv) < 4):
print('Error: missing arguments!')
print('e.g. python addPadding.py #AddedSlicesLowEnd #AddedSlicesHighEnd imageIn.nrrd [imageOut.nrrd]')
else:
Iin = str(sys.argv[3])
print('Processing %s...'% (Iin))
data1, header1 = nrrd.read(Iin)
sh = np.shape(data1)
Lpad = int(sys.argv[1])
Hpad = int(sys.argv[2])
data = np.zeros([sh[0],sh[1],sh[2]+Lpad+Hpad], dtype=np.uint8)
data[0:sh[0],0:sh[1],Lpad:Lpad+sh[2]] = data1
if (len(sys.argv) > 4):
Iout = str(sys.argv[4])
nrrd.write(Iout, data, options=header1)
print('saved to ' + Iout)
else:
Iout = Iin.replace(".nrrd", "_" + str(sh[2]) + ".nrrd")
nrrd.write(Iout, data1, options=header1)
print('original saved to ' + Iout)
nrrd.write(Iin, data, options=header1)
print('padded version saved to ' + Iin)