-
Notifications
You must be signed in to change notification settings - Fork 8
/
sitk_invert_scale_warp_field.py
executable file
·48 lines (41 loc) · 1.18 KB
/
sitk_invert_scale_warp_field.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
#!/usr/bin/env python
import SimpleITK as sitk
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"-s",
"--scale-factor",
type=float,
help="""
Scale inverted warp field by factor.
""",
)
parser.add_argument(
"input_warp_field",
type=str,
help="""
Input warp field.
""",
)
parser.add_argument(
"output_warp_field",
type=str,
help="""
Name to save inverted warp field.
""",
)
opts = parser.parse_args()
input_warp = sitk.ReadImage(opts.input_warp_field)
# output_warp = sitk.IterativeInverseDisplacementField(input_warp)
output_warp = sitk.InverseDisplacementField(input_warp)
if opts.scale_factor:
output_warp = sitk.Compose(
[
sitk.VectorIndexSelectionCast(output_warp, i) * opts.scale_factor
for i in range(output_warp.GetNumberOfComponentsPerPixel())
]
)
sitk.WriteImage(output_warp, opts.output_warp_field)