I used to convert nifti file to .vtk file but what I noticed that there are many versions.
I need # vtk DataFile Version 3.0
but this code gives me # vtk DataFile Version 4.2
.
import vtk
import sys
reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(sys.argv[1])
reader.Update()
print (reader)
contour=vtk.vtkMarchingCubes()
contour.SetInputData(reader.GetOutput())
contour.ComputeNormalsOn()
contour.ComputeGradientsOn()
contour.SetValue(0,0.1)
contour.Update()
# Write in vtk
triangle = vtk.vtkTriangleFilter()
triangle.SetInputConnection(contour.GetOutputPort())
triangle.PassVertsOff()
triangle.PassLinesOff()
decimation=vtk.vtkQuadricDecimation()
decimation.SetInputConnection(triangle.GetOutputPort())
clean=vtk.vtkCleanPolyData()
clean.SetInputConnection(triangle.GetOutputPort())
triangle2 = vtk.vtkTriangleFilter()
triangle2.SetInputConnection(clean.GetOutputPort())
triangle2.PassVertsOff()
triangle2.PassLinesOff()
#save .vtk polydata
writer = vtk.vtkPolyDataWriter()
writer.SetFileTypeToASCII()
writer.SetInputConnection(contour.GetOutputPort())
writer.SetFileName("1.vtk")
writer.Write()
what I get after runnig this code :
but what I need is
if you have noticed : the 4.2 file has 9 numbers as points but the other one 3.0 has only 3 which I have this error <<Details: cannot copy sequence with size 9 to array axis with dimension 3 >> when I want to display the image.
could someone help me !!