Issue with reading mhd image file

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.

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 in the toolkit’s notebook repository.

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)

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

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.

Hope you can help.

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 and see if the problem is resolved (possibly there never was a problem with the image but with the way it was displayed).

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.

1 Like