# Is it possible to convert to Hounsfield Units in Sitk?

**URL:** <https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061>\
**Category:** Beginner Questions\
**Tags:** dicom, ct, simpleitk\
**Created:** [June 7, 2022, 12:46am UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061 "2022-06-07T00:46:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DushiFdo](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@DushiFdo](https://discourse.itk.org/u/DushiFdo)\
**Post date:** [June 7, 2022, 12:46am UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/1 "2022-06-07T00:46:08Z")

</div>

Hi,

Is there a function in SITK to convert the pixel values in dicom CT images to Hounsfield Units (HU) ? This is what I currently do:

```python

def transform_to_hu(slices): 
    images = np.stack([file.pixel_array for file in slices]) #axis=-1 for depth in the last channel -> this yielded weired image
    images = images.astype(np.int16)

    images[images >= 1000] = 0

    for n in range(len(slices)):
        
        intercept = slices[n].RescaleIntercept
        slope = slices[n].RescaleSlope
        
        if slope != 1:
            images[n] = slope * images[n].astype(np.float64)
            images[n] = images[n].astype(np.int16)
            
        images[n] += np.int16(intercept)
    
    return np.array(images, dtype=np.int16), slices

```

I am specifically interested in clipping the values as follows: `images[images >= 1000] = 0`. When I do this on sitk to numpy converted images, it doesn’t work (plotted images are different).

---

<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:** [June 7, 2022, 1:18pm UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/2 "2022-06-07T13:18:24Z")

</div>

Hello @DushiFdo,

When reading a DICOM image/series of images everything is taken care of on the ITK/SimpleITK side. The result of reading a CT will be an image with intensities in HU.

You seem to be mixing and matching SimpleITK and pydicom concepts, this is not advisable. Highly recommend that you select one tool for reading DICOM and understand its conventions.

---

<div class="post-metadata">

**Author:** ![DushiFdo](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@DushiFdo](https://discourse.itk.org/u/DushiFdo)\
**Post date:** [June 7, 2022, 1:54pm UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/3 "2022-06-07T13:54:19Z")

</div>

Hi @zivy,

Thank you for the reply. Could you pleas tell me how to filter values in Sitk as ’ `images[images >= 1000] = 0` ?

---

<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:** [June 7, 2022, 2:05pm UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/4 "2022-06-07T14:05:51Z")

</div>

`image*(image<1000)`

---

<div class="post-metadata">

**Author:** ![Yogesh\_Kumar](https://discourse.itk.org/user_avatar/discourse.itk.org/yogesh_kumar/32/3633_2.png) [@Yogesh\_Kumar](https://discourse.itk.org/u/Yogesh_Kumar)\
**Post date:** [August 11, 2023, 6:08pm UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/6 "2023-08-11T18:08:21Z")

</div>

try  
images[images \> HU\_max] = HU\_max  
images[images \< HU\_min] = HU\_min

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [August 14, 2023, 12:56pm UTC](https://discourse.itk.org/t/is-it-possible-to-convert-to-hounsfield-units-in-sitk/5061/7 "2023-08-14T12:56:09Z")

</div>

This is a new feature in SimpleITK added for version 2.3.0 and available in the release candidates and nightly builds.
