[vtkusers] vtk image from itk
gregthom992
gregthom992 at gmail.com
Mon Jun 15 13:38:09 EDT 2015
Hi David ,
Thanks for your information. I ignored the origin and it didn't fix my
images.
I then made another attempt at a function to convert to vtk from SimpleITK.
This still gave me the "mangled" image. I am seeing that my img_array.shape
is [198 512 512] but my desired image Dimension should be [512 512 198]
Do you think that is the problem ? I am not sure how SimpleITK
GetArrayFromImage
does with flipping dimensions. Any help will be appreciated.
Greg
##CODE:
# image = sitk image
sitktype = image.GetPixelID()
vtktype = pixelmap[sitktype]
# Get ndarray from SimpleITK image
img_array = sitk.GetArrayFromImage(sitk.Cast(image, sitk.sitkFloat32))
Dimension = image.GetDimension()
OutputPixelType = itk.F
OutputImageType = itk.Image[OutputPixelType, Dimension]
#PyBuffer connector
pyBufferConnector = itk.PyBuffer[OutputImageType]
# Get ITK image from ndarray
itkImage = pyBufferConnector.GetImageFromArray(img_array)
# preserve ITK image information
itkImage.SetSpacing(image.GetSpacing())
#itkImage.SetOrigin(image.GetOrigin())
#itkImage.SetDirection(image.GetDirection())
itk_vtk_converter = itk.ImageToVTKImageFilter[OutputImageType].New()
itk_vtk_converter.SetInput(itkImage)
itk_vtk_converter.Update()
##END CODE
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtk-image-from-itk-tp5732315p5732342.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list