Bad saving in MET_UCHAR instead MET_UCHAR_ARRAY

Dear All,

I want that the image_3d be saved as MET_UCHAR_ARRAY and the code below saves in MET_UCHAR with only one component instead of three. How can be instructed the saving be done the right way?

Thanks,

Luís Gonçalves

  self.image_3d = vtk.vtkImageData()
    self.image_3d.SetDimensions(dim5)
    self.image_3d.SetSpacing(scale5)
    self.image_3d.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 3)
    points = self.image_3d.GetPointData()
    points.SetScalars(numpy_support.numpy_to_vtk(
    np.zeros((dim5[0]*dim5[1]*dim5[2]*3), dtype=np.uint8)))

    w = vtk.vtkMetaImageWriter()
    w.SetFileName(path1+file6+".mhd")
    w.SetInputData(self.image_3d)
    w.SetCompression(False)
    w.Write()

The “components” needs to be a separate dimension, try this instead:

np.zeros((dim5[0]*dim5[1]*dim5[2],3), dtype=np.uint8)))

You can remove the call to AllocateScalars() since SetScalars() will simply replace the allocated scalars with the new ones. In other words, setting the data type and number of components with AllocateScalars() is pointless if the allocated scalars are immediately replaced with new scalars.