Hey,
i’m new to vtk. i try to make a vtk image that contains a vtk complex array to create a nifti file with complex values in python. i used vtk.util.numpy_to_vtk to create an array, i know the function don’t support complex numbers and i was wondering if there is a way to fill the array with complex nubmers.
this is the code i’m currently using:
import numpy as np
from vtk.util import numpy_support
array = np.concatenate((np.real(numpy_array), np.imag(numpy_array)), axis=3)
stacked_array = array.reshape(-1, array.shape[-1])
vtk_array = numpy_support.numpy_to_vtk(stacked_array, deep=True, array_type=vtk.VTK_FLOAT)
vtk_image = vtk.vtkImageData()
vtk_image.SetDimensions(numpy_array.shape[0], numpy_array.shape[1], numpy_array.shape[2])
vtk_image.GetPointData().SetScalars(vtk_array)
writer = vtk.vtkNIFTIImageWriter()
writer.SetFileName(file_name)
writer.SetInputData(vtk_image)
writer.Write()
Thanks,
Shay