forked from KitwareMedical/TubeTK-pypbm
/
mapMRAToRef.py
143 lines (105 loc) · 4.47 KB
/
mapMRAToRef.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""mapMRAToRef.py
"""
__license__ = "Apache License, Version 2.0"
__author__ = "Roland Kwitt, Kitware Inc., 2013"
__email__ = "E-Mail: roland.kwitt@kitware.com"
__status__ = "Development"
import os
import sys
import pickle
import subprocess
from core import regtools
from optparse import OptionParser
def usage():
"""Print usage information"""
print("""
Take a list of spatial object files in MRA space and map them into the space of
the reference image by 1) mapping the objects into the space of the corresponding
MRI images and 2) applying a combination of AFFINE transformation + deformation
field to map them into the reference image space.
USAGE:
{0} [OPTIONS]
{0} -h
OPTIONS (Overview):
-l FILE
-c FILE
-t FILE
-i FILE0 FILE1 FILE2 FILE3
-x
OPTIONS (Detailed):
-l FILE
FILE should contain a list of absolute filenames of spatial object files
(i.e., the vessel trees), e.g.,
/tmp/vessels1.tre
/tmp/vessels2.tre
...
that will be mapped into the space of the reference image (specified as
an argument to -t - see below).
-c FILE
FILE is a configuration FILE in JSON format that contains the absolute
path's to all binaries that are used during the registration process.
For help, see the examplary configuration file config.json.example.
-x
Set this flag to FORCE the recomputation of all intermediate results. Be
careful with this option, since it might take a while to recompute all the
results.
-t FILE
Absolute path the the reference image to which all moving images are
registered to.
-i FILE0 FILE1 FILE2 FILE3
All files need to be in a format compatible with Python's pickle
functionality to load lists.
FILE0 should contain the list of all RIGID transformations that were
produced when registering the MRA to the MRI images (during mapping of
the spatial objects, the inverse of this transformation will be computed
and applied).
FILE1 should contain the list of all AFFINE transformations that were
produced when registering MRI images to the reference image. These are
usually the affine transformations that were produced during the ANTS
registration process (during mapping of the spatial objects, the inverse
of this transformation wil be computed and applied).
FILE2 should contain the list of FORWARD deformation fiels that were
produced during the ANTS registration process (MRI images to reference
image). These deformation fields are usually used to resample the moving
images (i.e., the MRI images in our case) into the space of the reference
image (currently these deformation fields are UNUSED).
FILE3 should contain the list of INVERSE deformation fields. These
deformation fields are used to refine the mapping of the spatial objects
(after applying the inverse affine transformations given in FILE2) in
the reference image space.
AUTHOR: Roland Kwitt, Kitware Inc., 2013
roland.kwitt@kitware.com
""".format(sys.argv[0]))
if __name__ == "__main__":
parser = OptionParser(add_help_option=False)
parser.add_option("-l", dest="vFiles")
parser.add_option("-c", dest="config")
parser.add_option("-t", dest="refImg")
parser.add_option("-i", dest="tFiles", action="store", nargs=4)
parser.add_option("-h", dest="doHelp", action="store_true", default=False)
parser.add_option("-x", dest="recomp", action="store_true", default=False)
options, args = parser.parse_args()
if options.doHelp:
usage()
sys.exit(-1)
if (options.vFiles is None or
options.config is None or
options.tFiles is None or
options.refImg is None):
usage()
sys.exit(-1)
helper = regtools.regtools(options.config)
vesselFileList = options.vFiles
vList0 = open(vesselFileList).readlines()
vList0 = [c.strip() for c in vList0]
T0ListFile, T1ListFile, FDListFile, IDListFile = options.tFiles
T0 = pickle.load(open(T0ListFile))
T1 = pickle.load(open(T1ListFile))
FD = pickle.load(open(FDListFile))
ID = pickle.load(open(IDListFile))
vList1 = helper.treeApplyTfm(vList0, T0, "RigidMRAToMRI", options.recomp)
vList2 = helper.treeApplyTfm(vList1, T1, "AffineMRIToRef", options.recomp)
vList3 = helper.treeApplyDfm(vList2, ID, "DeformRefToRef", options.recomp)
helper.createTreeImage(vList3,
[options.refImg]*len(vList3),
options.recomp)