-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotateRPI2LPS.py
More file actions
23 lines (22 loc) · 836 Bytes
/
rotateRPI2LPS.py
File metadata and controls
23 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
import sys, os
import nrrd
if (len(sys.argv) < 2):
print('Error: missing arguments!')
print('e.g. python rotateRPI2LPS.py imageIn.nrrd [ImageOut.nrrd]')
print('rotate RPI to LPS orientation for CMTK (as it doesn`t like RPI)')
else:
print('Processing %s...'% (str(sys.argv[1])))
data1, header1 = nrrd.read(str(sys.argv[1]))
print(header1)
header1['space'] = 'left-posterior-superior'
header1.pop("space dimension", None)
print(header1)
data2 = np.flip(data1, (0, 2))
print('saving...')
if (len(sys.argv) == 3):
nrrd.write(str(sys.argv[2]), data2, header1)
print('saved to ' + str(sys.argv[2]))
else:
nrrd.write(str(sys.argv[1]).replace('.nrrd','_LPS.nrrd'), data2, header1)
print('saved to ' + str(sys.argv[1]).replace('.nrrd','_LPS.nrrd'))