# writing mhd + raw instead of mhd +zraw

**URL:** <https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109>\
**Category:** Beginner Questions\
**Created:** [May 10, 2021, 1:45pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109 "2021-05-10T13:45:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![totoro3y](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@totoro3y](https://discourse.itk.org/u/totoro3y)\
**Post date:** [May 10, 2021, 1:45pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109/1 "2021-05-10T13:45:09Z")

</div>

Hello, I am using simpleitk to write mhd files using  
sitk.WriteImage(img, ‘file.mhd’)  
The output file is of mhd + zraw type.  
How can I generate mhd + raw files using simpleitk?

Thank you in advance!

---

<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:** [May 10, 2021, 4:27pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109/2 "2021-05-10T16:27:36Z")

</div>

`.zraw` is used when the file compression is enabled, `.raw` is used then file is uncompressed.

If it is a one-off thing, you could edit `.mhd` file and change the file name along with renaming the actual file.

---

<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:** [May 10, 2021, 5:01pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109/3 "2021-05-10T17:01:10Z")

</div>

Hello @totoro3y,

The default setting for `WriteImage`'s `useCompression` variable is `False` so surprising that your code creates a file with zraw extension. The following short snippet illustrates how the extension varies if compression is on or off:

```auto
import SimpleITK as sitk

img = sitk.ReadImage('training_001_ct.mha')

sitk.WriteImage(img,'with_compression.mhd', useCompression = True)
sitk.WriteImage(img,'no_compression.mhd')

```

---

<div class="post-metadata">

**Author:** ![totoro3y](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@totoro3y](https://discourse.itk.org/u/totoro3y)\
**Post date:** [June 30, 2021, 12:39pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109/4 "2021-06-30T12:39:43Z")

</div>

Hello, Thank you for sharing your reply. I tried as you said however, an error has raised.

> Traceback (most recent call last)  
> ----\> 2 sitk.WriteImage(out\_img, ‘out.mhd’,useCompression = True)  
> TypeError: WriteImage() got an unexpected keyword argument ‘useCompression’

Do you have any idea about that?  
Thank you!

---

<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 30, 2021, 12:49pm UTC](https://discourse.itk.org/t/writing-mhd-raw-instead-of-mhd-zraw/4109/5 "2021-06-30T12:49:55Z")

</div>

Hello @totoro3y,

Possibly a toolkit version issue. Code looks good and works with the latest SimpleITK release, version 2.0.2.
