Set dtype of written Nifti image


I am working on exporting a segmentation as a nifti image, for which I use the vtkNiftiImageWriter.
These nifti images have structured dtype:= [(R, uint8) (G, uint8), (b, uint8), (A, uint8)]

Now, I am interfacing with code that uses nibabel and numpy to manipulate the images, which should have a non-structured type (e.g.: float64).

I understand this might be the wrong place to ask, but still would like to know if there is a way to cast and write the images in a non-structured type with vtk, or how to cast the type to a non-structured one that will be interpreted properly afterwards.

Thanks for your time & thanks in advance

Use vtkImageCast with SetOutputScalarTypeToDouble(), and then use vtkNIFTIImageWriter to write the image. The resulting file will have a dtype of float64 and will have an extra dimension to handle the R,G,B,A components.

1 Like

Thank you as always!