Antspy三个API:
- image_read
- from_numpy
- image_write
image_read
import ants
file = '../T1.nii'
data = ants.image_read(file)
ants.plot(data)
from_numpy
get numpy
arr = data.numpy()
arr.shape
# (240, 240, 155)
此处的shape为:( x , y , z )
save numpy
- spacing
- direction
上面两个参数必不可少。
save_img = ants.from_numpy(arr, spacing=data.spacing, direction=data.direction)
ants.image_write(save_img, 'new.nii.gz')
~~