-
Notifications
You must be signed in to change notification settings - Fork 0
/
antsRegistrationExampleCommand.py
74 lines (54 loc) · 2.63 KB
/
antsRegistrationExampleCommand.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
import ants
import os
dataDirectory = './InputData/'
fixedImage = ants.image_read( dataDirectory + 'r16sliceWithCircle.nii.gz', dimension = 2 )
fixedMask = ants.image_read( dataDirectory + 'r16mask.nii.gz', dimension = 2 )
movingImage = ants.image_read( dataDirectory + 'r64sliceWithSquare.nii.gz', dimension = 2 )
movingMask = ants.image_read( dataDirectory + 'r64mask.nii.gz', dimension = 2 )
# Plot the fixed image/mask
ants.plot( fixedImage, overlay = fixedMask, overlay_cmap = "viridis", alpha = 0.9 )
# Plot the moving image/mask
ants.plot( movingImage, overlay = movingMask, overlay_cmap = "viridis", alpha = 0.9 )
#######
#
# Perform registration with no mask
#
outputDirectory = './OutputNoMaskANTsPy/'
if not os.path.isdir( outputDirectory ):
os.mkdir( outputDirectory )
outputPrefix = outputDirectory + 'antsr'
registrationNoMask = ants.registration(
fixed = fixedImage, moving = movingImage,
type_of_transform = "SyNOnly",
regIterations = ( 100, 75, 20, 0 ),
verbose = True, outprefix = outputPrefix )
ants.image_write( registrationNoMask['warpedmovout'], outputPrefix + "Warped.nii.gz" )
ants.image_write( registrationNoMask['warpedfixout'], outputPrefix + "InverseWarped.nii.gz" )
# Plot the fixed and warped moving image
ants.plot( fixedImage, overlay = registrationNoMask['warpedmovout'], overlay_cmap = "viridis", alpha = 0.9 )
# Plot the moving and warped fixed image
ants.plot( movingImage, overlay = registrationNoMask['warpedfixout'], overlay_cmap = "viridis", alpha = 0.9 )
jacobian = ants.create_jacobian_determinant_image( fixedImage, registrationNoMask['fwdtransforms'][0] )
ants.plot( jacobian )
#######
#
# Perform registration with mask
#
outputDirectory = './OutputWithMaskANTsPy/'
if not os.path.isdir( outputDirectory ):
os.mkdir( outputDirectory )
outputPrefix = outputDirectory + 'antsr'
registrationWithMask = ants.registration(
fixed = fixedImage, moving = movingImage,
mask = fixedMask,
type_of_transform = "SyNOnly",
regIterations = ( 100, 75, 20, 0 ),
verbose = True, outprefix = outputPrefix )
ants.image_write( registrationWithMask['warpedmovout'], outputPrefix + "Warped.nii.gz" )
ants.image_write( registrationWithMask['warpedfixout'], outputPrefix + "InverseWarped.nii.gz" )
# Plot the fixed and warped moving image
ants.plot( fixedImage, overlay = registrationWithMask['warpedmovout'], overlay_cmap = "viridis", alpha = 0.9 )
# Plot the moving and warped fixed image
ants.plot( movingImage, overlay = registrationWithMask['warpedfixout'], overlay_cmap = "viridis", alpha = 0.9 )
jacobian = ants.create_jacobian_determinant_image( fixedImage, registrationWithMask['fwdtransforms'][0] )
ants.plot( jacobian )