# Issue with reading mhd image file

**URL:** https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038
**Category:** Beginner Questions
**Tags:** image, simpleitk
**Created:** [April 15, 2021, 9:25am UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038 "2021-04-15T09:25:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![spb](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@spb](https://discourse.itk.org/u/spb)
#### Post date: [April 15, 2021, 9:25am UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038/1 "2021-04-15T09:25:28Z")

</div>

Hi,

I am reading mhd image file in python using SimpleITK as follows.

sitkimage = sitk.ReadImage(mhdFile)

The issue is, after reading image, size is changed.

Original Image  
(width, height, depth) → (1024, 512, 128)

Read Image  
(width, height, depth) → (512,1024, 128)

Height and width are interchanged, why is this happening?

Thanks in advance.

---

<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: [April 15, 2021, 12:38pm UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038/2 "2021-04-15T12:38:14Z")

</div>

Hello @spb,

How are you obtaining the original image size? In SimpleITK the index order is [x,y,z], unlike for instance numpy for which the same data has an index order of [z,y,x].

For additional details and a general introduction to images in SimpleITK please see the [Image Details notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/03_Image_Details.ipynb) in the toolkit’s [notebook repository](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks).

---

<div class="post-metadata">

### Author: ![spb](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@spb](https://discourse.itk.org/u/spb)
#### Post date: [April 15, 2021, 1:34pm UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038/3 "2021-04-15T13:34:23Z")

</div>

Hi zivy,

Thanks for you reply. I think the issue is not with index order.

The original image looks like this with dimension (HEIGHT=512, WIDTH=1024, DEPTH=128)

 ![Screenshot from 2021-04-15 18-51-17](https://discourse.itk.org/uploads/default/original/2X/a/a5a1f20ea4b35325e3f0e41876e257cdf514eba8.png)

But the image read by SimpleITK is other way (HIEGHT=1024, WIDTH=512, DEPTH=128).

 ![download (11)](https://discourse.itk.org/uploads/default/original/2X/c/c60eea05caad2cbff21bd9beed9a26dffcfb305b.png)

As suggested, I tried reversing index order by transpose image like this, but it didn’t work as expected.

sitkimage = sitk.GetArrayFromImage(sitk.ReadImage(mhdFile)).transpose(0, 2, 1), image looks like this.

 ![download (12)](https://discourse.itk.org/uploads/default/original/2X/f/f856f9b2dbf975032b28d9ee592a220db041286a.jpeg)

Hope you can help.

---

<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: [April 15, 2021, 1:42pm UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038/4 "2021-04-15T13:42:58Z")

</div>

Hello @spb ,

You are mixing two things here, the image data structure and the way the display program interprets the data. Please take a look at the [Image Display notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/04_Image_Display.ipynb) and see if the problem is resolved (possibly there never was a problem with the image but with the way it was displayed).

---

<div class="post-metadata">

### Author: ![spb](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@spb](https://discourse.itk.org/u/spb)
#### Post date: [April 17, 2021, 6:28am UTC](https://discourse.itk.org/t/issue-with-reading-mhd-image-file/4038/5 "2021-04-17T06:28:19Z")

</div>

Hi zivy,

Issue is resolved. As you said there is no problem with reading image, but while displaying image, element spacings were not considered. With proper element spacing I am able to reproduce the original image.

Thank you.
