# converting pixel type of dicom series and saving them

**URL:** <https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763>\
**Category:** Algorithms\
**Created:** [April 9, 2019, 11:53am UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763 "2019-04-09T11:53:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Festugato](https://discourse.itk.org/user_avatar/discourse.itk.org/marco_festugato/32/696_2.png) [@Marco\_Festugato](https://discourse.itk.org/u/Marco_Festugato)\
**Post date:** [April 9, 2019, 11:53am UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763/1 "2019-04-09T11:53:59Z")

</div>

Hello there,

for my purposes I had to load a 2D dicom series (I used the example DicomSeriesReadSeriesWrite) and create a volume, then I had to change pixel format because my filter accepts only ‘float’ type. I used the CastImageFilter for this, and the RescaleIntensityImageFilter to scale my image between 0 and 255… would it be better for filtering and mathematical operations to put the range between 0 and 1? Do I really have to rescale the original intensity (-3200 and 3200) ?

Now I have to save the filtered volume into 2D slices, so I have to change again the pixel type into the original one…do I need to rescale the intensity into the original -3200, +3200? Or can i leave it between 0 - 255? Does it change something?

Thanks in advance for any help!

---

<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:** [April 9, 2019, 1:20pm UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763/2 "2019-04-09T13:20:48Z")

</div>

> [@Marco\_Festugato](#):
>
> my filter accepts only ‘float’ type

Is it a filter you wrote? Or a colleague? And why is `float` a problem? You can cast all scalar types into `float` without much trouble. You could also request reading a `float` image type from the reader and have that image type throughout your pipeline.

And your output could be in the same range as input, or a different range. It depends on what you want to do with your images afterwards.

---

<div class="post-metadata">

**Author:** ![Marco\_Festugato](https://discourse.itk.org/user_avatar/discourse.itk.org/marco_festugato/32/696_2.png) [@Marco\_Festugato](https://discourse.itk.org/u/Marco_Festugato)\
**Post date:** [April 9, 2019, 1:46pm UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763/3 "2019-04-09T13:46:30Z")

</div>

Thank you @dzenanz for answering once again. Nope, it’s the itkCurvatureFlowImageFilter that I want to use (for what i know, it requires ‘float’ type).

Do u know how could i restore the initial range of the dicom series if I want to? Also, do u know if rescaling the range (maybe between 0 and 1) is better for filtering/mathematical operations?  
Sorry for my english and thanks in advance for all your help and support!

---

<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:** [April 9, 2019, 2:00pm UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763/4 "2019-04-09T14:00:35Z")

</div>

Judging by its [documentation](https://itk.org/Doxygen/html/classitk_1_1CurvatureFlowImageFilter.html), `CurvatureFlowImageFilter` is not restricted to `float` type. You should be able to use it with `double`, `int`, `unsigned char` etc.

Range 0.0-1.0 is not better than other ranges for filtering.

If you use [RescaleIntensityImageFilter](https://itk.org/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html), you can then use [GetScale()](https://itk.org/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html#a2d603acb004c872691aebb0c18484ee3) and [GetShift()](https://itk.org/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html#afedb9d67ab07f598cd50f8468fa79362) methods to know the scaling and offset which that filter applied. Then you can work out the inverse intensity transform, and apply it using [ShiftScaleImageFilter](https://itk.org/Doxygen/html/classitk_1_1ShiftScaleImageFilter.html), in order to transform filtered values back to the original range of intensities.

---

<div class="post-metadata">

**Author:** ![Marco\_Festugato](https://discourse.itk.org/user_avatar/discourse.itk.org/marco_festugato/32/696_2.png) [@Marco\_Festugato](https://discourse.itk.org/u/Marco_Festugato)\
**Post date:** [April 9, 2019, 2:11pm UTC](https://discourse.itk.org/t/converting-pixel-type-of-dicom-series-and-saving-them/1763/5 "2019-04-09T14:11:34Z")

</div>

Perfect! Thank u!
