# SimpleITK doesn't seem to apply rescale intercept/slop

**URL:** https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [January 15, 2021, 7:07pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768 "2021-01-15T19:07:04Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![malteekj](https://discourse.itk.org/user_avatar/discourse.itk.org/malteekj/32/1589_2.png) [@malteekj](https://discourse.itk.org/u/malteekj)
#### Post date: [January 15, 2021, 7:07pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/1 "2021-01-15T19:07:04Z")

</div>

I’m using the SimpleITK API for python to load medical images in DICOM format (PET and CT). However, it appears that SimpleITK doesn’t apply the rescale slope and rescale intercept. My code right now is:

```python
import SimpleITK as sitk

root_pet = 'path_dicom_files'

reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(root_pet)

reader.SetFileNames(dicom_names)
reader.MetaDataDictionaryArrayUpdateOn()
reader.LoadPrivateTagsOn()

imagePET = reader.Execute()
pet_array = sitk.GetArrayFromImage(imagePET) 

```

However, the range is: [-31796.78, 31074.89], but it should be [0, 4883997.44]. Can anyone help as to why the PET image is not rescaled? It seems like it’s still in the int32 format right now.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [January 15, 2021, 8:46pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/2 "2021-01-15T20:46:30Z")

</div>

Hello @malteekj,

I don’t think that is the problem (not applying slope intercept), as we have used SimpleITK in the past to read PET images. Can you possibly share the data so that we look into it? Otherwise we have no way of pinpointing the problem.

Finally, given the range of values you provided the image pixel type is likely float32, but not int32.

---

<div class="post-metadata">

### Author: ![malteekj](https://discourse.itk.org/user_avatar/discourse.itk.org/malteekj/32/1589_2.png) [@malteekj](https://discourse.itk.org/u/malteekj)
#### Post date: [January 20, 2021, 2:30pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/3 "2021-01-20T14:30:33Z")

</div>

Hi @zivy,

Thanks for the answer. I have uploaded a sample PET image (159 slices):

> **[1.2.826.0.1.3417726.3.30343.20201008132234488 - Google Drive](https://drive.google.com/drive/folders/1FJzyjmxu8N49fBg4DT4aYChiXwaJC9yS?usp=sharing)**

The file is a PET image of a 2 mice with subcutaneous tumors.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [January 20, 2021, 2:56pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/4 "2021-01-20T14:56:39Z")

</div>

Hello @malteekj,

I just tried the following minimal example (not recommended as assumes a single series in the current working directory) and it reports a range of [0, 4883997.44304984] for your volume:

```auto
import SimpleITK as sitk

print(sitk.Version())

image = sitk.ReadImage(sitk.ImageSeriesReader_GetGDCMSeriesFileNames('.'))
print(sitk.GetArrayViewFromImage(image).min())
print(sitk.GetArrayViewFromImage(image).max())

```

Which version of SimpleITK are you using? Possibly there is a bug in your code reporting the min/max of the data? As that wasn’t provided, I am only guessing here.

---

<div class="post-metadata">

### Author: ![malteekj](https://discourse.itk.org/user_avatar/discourse.itk.org/malteekj/32/1589_2.png) [@malteekj](https://discourse.itk.org/u/malteekj)
#### Post date: [January 20, 2021, 3:57pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/5 "2021-01-20T15:57:42Z")

</div>

I have tried to update simpleITK and apply your code, and I get the same results as you now. Thanks for the help!

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [January 20, 2021, 9:49pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/6 "2021-01-20T21:49:03Z")

</div>

There is one empty file `1.2.826.0.1.3417726.3.798598.20201008132235010.dcm` with slope/intercept 1/0 and all values are 0. You can try to remove the file, it will not break uniformity of the image (it is edge). May be it will work better without the file, such files sometimes make difficulties with calculation of output pixel type and it is already not easy for PET, because for every slice may be _different slope/intercept_. Didn’t try with SimpleITK, not sure it helps, but FYI.

**Edit** :  
in my app min/max is exactly the same as reported in above post [0, 4883997.44304984], output data type is _double_.

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [January 21, 2021, 12:43am UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/7 "2021-01-21T00:43:15Z")

</div>

Sorry, off-topic, not related to user question  
@zivy could you kindly test what min/max values you get if the same series is opened in [multi-frame DICOM file](https://drive.google.com/file/d/1PxsdAbeKLLd_cKqg-357HmggqQ8s3WLI/view?usp=sharing) (converted to _Legacy Converted Enhanced PET Image Storage_ with D.Clunie’s java class). I am afraid there is a bug. Thank you.

**Edit** : GDCM takes for multi-frame file slope/intercept from _Shared Functional Groups Sequence_ or **1st frame** in _Per-frame Functional Groups Sequence_ and applies to the whole image, but they are different for every frame (specially PET). S. [here](https://github.com/InsightSoftwareConsortium/ITK/blob/f72026ae9a4fbd3d1fddb5f3c4ba2d77c751f951/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx#L971) and [here](https://github.com/InsightSoftwareConsortium/ITK/blob/f72026ae9a4fbd3d1fddb5f3c4ba2d77c751f951/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx#L138).

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [January 21, 2021, 2:47pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/8 "2021-01-21T14:47:03Z")

</div>

Hello @mihail.isakov,

Thanks for looking into this. Given that this is a GDCM issue, please post it on the [gdcm-developers mailing list](https://sourceforge.net/p/gdcm/mailman/).

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [January 22, 2021, 2:32pm UTC](https://discourse.itk.org/t/simpleitk-doesnt-seem-to-apply-rescale-intercept-slop/3768/9 "2021-01-22T14:32:14Z")

</div>

@zivy Thank you. Sorry, my projects are not affected, i’ll not do anything with the issue in the near future. It was just FYI, because ITK/SimpleITK IO are probably affected.
