# Set dtype of written Nifti image

**URL:** https://discourse.vtk.org/t/set-dtype-of-written-nifti-image/10923
**Category:** Support
**Tags:** python
**Created:** [March 8, 2023, 6:57pm UTC](https://discourse.vtk.org/t/set-dtype-of-written-nifti-image/10923 "2023-03-08T18:57:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Valentin\_Regueiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/valentin_regueiro/32/4419_2.png) [@Valentin\_Regueiro](https://discourse.vtk.org/u/Valentin_Regueiro)
#### Post date: [March 8, 2023, 6:57pm UTC](https://discourse.vtk.org/t/set-dtype-of-written-nifti-image/10923/1 "2023-03-08T18:57:19Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 8, 2023, 7:14pm UTC](https://discourse.vtk.org/t/set-dtype-of-written-nifti-image/10923/2 "2023-03-08T19:14:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Valentin\_Regueiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/valentin_regueiro/32/4419_2.png) [@Valentin\_Regueiro](https://discourse.vtk.org/u/Valentin_Regueiro)
#### Post date: [March 14, 2023, 9:55am UTC](https://discourse.vtk.org/t/set-dtype-of-written-nifti-image/10923/3 "2023-03-14T09:55:47Z")

</div>

Thank you as always!
