I am writing a code to read a nifiti file with python code, convert it to vtk format, and save it again. When I display the output result in a slicer, the location is different. Below is the output result (original in red) and the code. I would appreciate your help.
import nibabel as nib
import numpy as np
import vtk
import vmtk.vtkvmtkMiscPython as vtkvmtkMisc
from vtk.util import numpy_support
import matplotlib.pyplot as plt
input_nifti = 'artery1_obj_1.nii.gz'
msk_name='output_test.vtk'
reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(input_nifti)
reader.Update()
cast = vtk.vtkImageCast()
cast.SetInputData(reader.GetOutput())
cast.SetOutputScalarTypeToFloat()
cast.Update()
mc = vtk.vtkMarchingCubes()
mc.SetInputData(cast.GetOutput())
mc.ComputeNormalsOn()
mc.SetValue(0,0.5)
mc.Update()
transform = vtk.vtkTransform()
if reader.GetQFormMatrix():
transform.Concatenate(reader.GetQFormMatrix())
elif reader.GetSFormMatrix():
transform.Concatenate(reader.GetSFormMatrix())
tpd = vtk.vtkTransformPolyDataFilter()
tpd.SetInputData(mc.GetOutput())
tpd.SetTransform(transform)
tpd.Update()
writer = vtk.vtkPolyDataWriter()
writer.SetInputData(tpd.GetOutput())
writer.SetFileName(msk_name)
writer.Update()