-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.py
29 lines (25 loc) · 1.11 KB
/
registration.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
import SimpleITK as sitk
from types import SimpleNamespace
import os
class run():
def __init__(self, **kwargs):
defaultKwargs = {}
args = SimpleNamespace(**{**defaultKwargs, **kwargs})
elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetLogToConsole(False)
elastixImageFilter.SetFixedImage(sitk.ReadImage(args.reference))
elastixImageFilter.SetMovingImage(sitk.ReadImage(args.in_file))
parameterMapVector = sitk.VectorOfParameterMap()
# Apply translation
parameterMapVector.append(sitk.GetDefaultParameterMap("translation"))
# Apply rigid
parameterMapVector.append(sitk.GetDefaultParameterMap("rigid"))
# Apply affine
parameterMapVector.append(sitk.GetDefaultParameterMap("affine"))
elastixImageFilter.SetParameterMap(parameterMapVector)
elastixImageFilter.Execute()
# Remove temporary files
for i in [0, 1, 2]:
os.remove(f'TransformParameters.{i}.txt')
# Save registered image
sitk.WriteImage(elastixImageFilter.GetResultImage(), args.out_file)