0
我正在閱讀SimpleITK的圖像,但我在vtk中獲得這些結果有幫助嗎? 我不確定這裏發生了什麼事情。itk的vtk的mangle圖像
請參閱圖像here。
####
CODE
def sitk2vtk(img):
size = list(img.GetSize())
origin = list(img.GetOrigin())
spacing = list(img.GetSpacing())
sitktype = img.GetPixelID()
vtktype = pixelmap[sitktype]
ncomp = img.GetNumberOfComponentsPerPixel()
# there doesn't seem to be a way to specify the image orientation in VTK
# convert the SimpleITK image to a numpy array
i2 = sitk.GetArrayFromImage(img)
#import pylab
#i2 = reshape(i2, size)
i2_string = i2.tostring()
# send the numpy array to VTK with a vtkImageImport object
dataImporter = vtk.vtkImageImport()
dataImporter.CopyImportVoidPointer(i2_string, len(i2_string))
dataImporter.SetDataScalarType(vtktype)
dataImporter.SetNumberOfScalarComponents(ncomp)
# VTK expects 3-dimensional parameters
if len(size) == 2:
size.append(1)
if len(origin) == 2:
origin.append(0.0)
if len(spacing) == 2:
spacing.append(spacing[0])
# Set the new VTK image's parameters
#
dataImporter.SetDataExtent (0, size[0]-1, 0, size[1]-1, 0, size[2]-1)
dataImporter.SetWholeExtent(0, size[0]-1, 0, size[1]-1, 0, size[2]-1)
dataImporter.SetDataOrigin(origin)
dataImporter.SetDataSpacing(spacing)
dataImporter.Update()
vtk_image = dataImporter.GetOutput()
return vtk_image
###
END CODE
嗨siavashk,謝謝你的回答。正如我在vtk-users列表中所指出的......我發現了罪魁禍首! 我正在將ImageSeriesReader以外計算的文件名列表傳遞給ImageSeriesReader。我曾以爲它會爲我排序文件名,但它不會。 現在,我使用dcm_series_filenames = reader.GetGDCMSeriesFileNames(dcm_dir,seriesUID),然後是reader.SetFileNames(dcm_series_filenames),因爲我已經獲得了seriesUID和文件列表 – user1301295