里面的数据形式得是vtkimagedata形式才可以
VTK转numpy
nshape = tuple(reversed(mergedImage.GetDimensions()))
label_array = vtk.util.numpy_support.vtk_to_numpy(mergedImage.GetPointData().GetScalars()).reshape(nshape)
label_array=label_array.astype(np.int8)
numpy转VTK
pred_label_numpy=np.load("/home/chenxiaohui/project/test/pred_label.npy")
data_vtk = numpy_support.numpy_to_vtk(pred_label_numpy.ravel(),array_type=vtk.VTK_UNSIGNED_CHAR)
vimage = vtk.vtkImageData()
vshape = tuple(reversed(pred_label_numpy.shape))
vimage.SetDimensions(vshape)
vimage.GetPointData().SetScalars(data_vtk)
vimage.SetSpacing(mergedImage.GetSpacing())
vimage.SetOrigin(mergedImage.GetOrigin())