# Convert image dtypes

**URL:** https://discourse.itk.org/t/convert-image-dtypes/5389
**Category:** Beginner Questions
**Created:** [October 6, 2022, 10:45am UTC](https://discourse.itk.org/t/convert-image-dtypes/5389 "2022-10-06T10:45:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JonB](https://discourse.itk.org/user_avatar/discourse.itk.org/jonb/32/2975_2.png) [@JonB](https://discourse.itk.org/u/JonB)
#### Post date: [October 6, 2022, 10:45am UTC](https://discourse.itk.org/t/convert-image-dtypes/5389/1 "2022-10-06T10:45:36Z")

</div>

Hi there,

I have a problem regarding storage of transformed images.  
I applied several filters on 3D images and now I see after transformation the dtype changed because of the transformation from int16 (original image) to float32 (transformed image).

My question is: how to reduce the space for the images but not loose too much information (as these float values can not be stored in int)?

`sitk.GetArrayFromImage((original_img)[82,:,:])`  
array([[-1024, -1024, -1024, …, -1024, -1024, -1024],  
[-1024, -1024, -1024, …, -1024, -1024, -1024],  
[-1024, -1024, -1024, …, -1024, -1024, -1024],  
…,  
[-1024, -1024, -1024, …, -1024, -1024, -1024],  
[-1024, -1024, -1024, …, -1024, -1024, -1024],  
[0, 0, 0, …, 0, 0, 0]], dtype=int16)

`sitk.GetArrayFromImage((LoG_img)[82,:,:])`  
array([[ 3.80310001e-14, 3.88584726e-13, -2.41688917e-12, …,  
6.98954403e-13, -3.71507295e-14, -1.73147141e-13],  
[ 3.66081982e-14, 3.88977452e-13, -2.46619435e-12, …,  
6.82724547e-13, -4.15325665e-15, -1.72151532e-13],  
[ 5.34215142e-14, 4.18245950e-13, -2.53347083e-12, …,  
6.88941092e-13, 3.52969641e-14, -1.56478942e-13],  
…,  
[ 4.03164481e-13, 1.00738938e-12, -5.48105008e-12, …,  
5.36486166e-13, -9.33539677e-14, -1.66741566e-13],  
[ 3.93933394e-13, 1.02557459e-12, -5.49871173e-12, …,  
5.96517898e-13, -1.19890073e-13, -1.71319800e-13],  
[ 3.74245448e-13, 1.00267516e-12, -4.71460111e-12, …,  
6.80374431e-13, -1.12430275e-13, -1.70331753e-13]], dtype=float32)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 6, 2022, 12:45pm UTC](https://discourse.itk.org/t/convert-image-dtypes/5389/2 "2022-10-06T12:45:14Z")

</div>

Of the image formats ITK supports, I think only DICOM can avoid writing 32 bits per pixel (by writing 16-bit ints in the pixel buffer, combined with float rescale slope and intercept). Much easier is to enable compression - most formats support it.
