使用ipython定义一个空的ITK映像
我试图在iPython笔记本电脑上定义一个特定3D大小的空ITK图像,我一直在定义所谓的:使用ipython定义一个空的ITK映像,python,ipython,ipython-notebook,itk,Python,Ipython,Ipython Notebook,Itk,我试图在iPython笔记本电脑上定义一个特定3D大小的空ITK图像,我一直在定义所谓的: 'itkIndex3' index 我已经为itk和vtk加载了所有python绑定,并定义了不同的类型(在本例中是大小为80、体素大小为0.5 mm的浮点三维图像),但仍然无法用任何值填充它。以下是代码,您可以查看: # Tools for Biomedical Imaging import nibabel as nib import itk import vtk start = itk.Index
'itkIndex3' index
我已经为itk和vtk加载了所有python绑定,并定义了不同的类型(在本例中是大小为80、体素大小为0.5 mm的浮点三维图像),但仍然无法用任何值填充它。以下是代码,您可以查看:
# Tools for Biomedical Imaging
import nibabel as nib
import itk
import vtk
start = itk.Index[3]
size = itk.Size[3]
start.Fill(0)
-----------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/administrator/<ipython-input-63-8774101ef8fb> in <module>()
1 start = itk.Index[3]
2 size = itk.Size[3]
----> 3 start.Fill(0)
Fill() must be called with itkIndex3 instance as first argument (got int instance instead)
嗨!,我想我能够用一种不同的方法解决这个问题,我将包括我用来创建3D浮动图像的代码,让每个人都能看到;)
我认为它不起作用的原因只是因为我没有直接把它写成向量。在ITK中,它们是以不同的方式执行的:该错误通常意味着您试图使用一个类对象,而您应该使用该类的实例。您可以尝试
start().Fill(0)
,但我对ITK一无所知。我更改了两项内容,现在它似乎工作正常!谢谢你的回答!并检查上面的解决方案!
-------------------------------------------------------------------
-------------------------------------------------------------------
nii_PixelType = itk.F # Read the image, also possible using nibabel
nii_ImageType = itk.Image[nii_PixelType, 3]
def CreateBaseAtlas(total_Size):
# Created based on the code in:
# http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter
image = nii_ImageType.New()
_start=[0,0,0]
_size=[total_Size,total_Size,total_Size]
_region = itk.ImageRegion._3(_start,_size)
image.SetRegions(_region)
image.Allocate()
image.FillBuffer(0)
return image