# Slicer loads wrong image spacing

**URL:** <https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453>\
**Category:** Support\
**Created:** [June 7, 2017, 4:35pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453 "2017-06-07T16:35:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shilpa\_Ananth](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Shilpa\_Ananth](https://discourse.slicer.org/u/Shilpa_Ananth)\
**Post date:** [June 7, 2017, 4:35pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/1 "2017-06-07T16:35:07Z")

</div>

Operating system: Windows 64 bit  
Slicer version: 4.6.2  
Expected behavior: My .dcm file has clear values under the Pixel spacing and the Slice thickness,spacing between slices tags. So these values must be loaded onto image spacing under ‘volumes’.  
Actual behavior: Image spacing goes to default value ie 1mm 1mm and 1mm.

Are there any other tags required for this field that I am forgetting to include in my dicom header? I cannot manually change it everytime as I am trying to integrate it with a different process.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 7, 2017, 5:47pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/2 "2017-06-07T17:47:28Z")

</div>

You are making these dicom files yourself? If so maybe you have not encoded the elements correctly. You can try loading the sample data below and compare your data.

[http://slicer.kitware.com/midas3/download/item/279888/deidentifiedMRHead.zip](http://slicer.kitware.com/midas3/download/item/279888/deidentifiedMRHead.zip)

Also note if you are looking at the vtkImageData on a loaded node, it will have origin 0,0,0 and spacing 1,1,1 because there’s no way to encode orientation in a vtkImageData. Instead, location of the imaging data in patient space is encoded in the mrml IJKToRAS and transform elements.

[https://www.slicer.org/wiki/Coordinate\_systems](https://www.slicer.org/wiki/Coordinate_systems)

---

<div class="post-metadata">

**Author:** ![Shilpa\_Ananth](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Shilpa\_Ananth](https://discourse.slicer.org/u/Shilpa_Ananth)\
**Post date:** [June 7, 2017, 7:21pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/3 "2017-06-07T19:21:56Z")

</div>

Thanks for your response!

Not exactly myself, but im just rearranging data. The DICOM header is stored as a dataset with elements. However, my data had a few elements itself as datasets. So I had to bring a few elements back into the main dataset. I was able to successfully bring proper values on slicer with respect to origin. This seems to take information from the Image position(Patient) Tag.

But even though the tags required for Spacing are now present as elements in the main dataset- Pixel spacing, slice thickness, and most of the other relevant data that is included in the header of the file you uploaded, The spacing still shows 1mm 1mm and 1mm. I am not using vtk.

Is there any information as to which tags exactly slicer draws the information from for image spacing? Intuitively it should be the two elements of Pixel spacing and the third element should be slice thickness.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 7, 2017, 8:23pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/4 "2017-06-07T20:23:03Z")

</div>

Hi -

PixelSpacing should always give the in-plane sizes in mm. Be sure it is in a valid dicom format of two DS values (basically decimal strings separated by backslash).

If you use dcmdump from dcmtk it should look something like this:

```
(0028,0030) DS [1.000000e+00\1.000000e+00] # 26, 2 PixelSpacing
```

The out of plane spacing is defined by the distance between the ImagePositionPatient of adjacent slices, not by the SliceThickness, which can be different for a variety of reasons.

If Slicer (or ITK) can’t parse what your file contains you could end up with spacings of 1,1,1.

It’s a slightly different context, but this blog post gives you some background and context:

> **[How Thick am I? The Sad Story of a Lonely Slice.](http://dclunie.blogspot.com/2013/10/how-thick-am-i-sad-story-of-lonely-slice.html)**
>
> Summary: Single slice regions of interest with no multi-slice context or interval/thickness information may need to be reported as area only...

HTH,  
Steve

---

<div class="post-metadata">

**Author:** ![Shilpa\_Ananth](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Shilpa\_Ananth](https://discourse.slicer.org/u/Shilpa_Ananth)\
**Post date:** [June 8, 2017, 2:16pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/5 "2017-06-08T14:16:46Z")

</div>

Thanks steve!

I’ve checked, and the slice thickness even coincides with the distance between the imagepositionpatient of adjacent slices.  
And the pixel spacing seems to be the right format.Here is my ouput from python: I am using the pydicom toolbox.

> > original\_image.data\_element(“PixelSpacing”).value  
> > [‘0.65562321835365’, ‘0.65562321835365’]

The image is a multiframe image. Is that the problem? It had its image position patient of each slice under per frame functional group sequence! So maybe it is unable to find the proper spacing?

Shilpa

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 8, 2017, 7:04pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/6 "2017-06-08T19:04:09Z")

</div>

Hi -

Multiframe DICOM images should be loadable in Slicer – is there any chance  
you can share a deidentified example? Yes, having the ImagePositionPatient  
values in the per-frame functional groups is the right place and Slicer  
should be looking there.

-Steve

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 8, 2017, 7:53pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/7 "2017-06-08T19:53:05Z")

</div>

Reading spacing correctly for multi-frame volumes has been added to ITK a couple of years ago. It might have broken since, as probably automatic testing of DICOM parsing is quite limited in ITK. Probably we should add tests for that in Slicer.

---

<div class="post-metadata">

**Author:** ![Shilpa\_Ananth](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Shilpa\_Ananth](https://discourse.slicer.org/u/Shilpa_Ananth)\
**Post date:** [June 8, 2017, 8:40pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/8 "2017-06-08T20:40:55Z")

</div>

Unfortunately, I won’t be able to do that(share the image). This is an abdominal CT from Philips medical systems. I did download another standard multiframe from nema onto slicer and that does give proper values in the volume fields lifted right off the header but the rendered volume is well away from the origin of the RAS (The pink box) .

The nema image and this image does have a few differences. for example, the  
(5200, 9229) Shared Functional Groups Sequence 1 item(s) ----  
tag in my file does not have image orientation under the plane orientation sequence. My file has it just under all the per-frame functional groups. A couple of other extra tags were there under (5200,9299) for the nema image too! These were absent from mine.

However 5200,9229 does have the  
(0028, 9110) Pixel Measures Sequence 1 item(s) ----  
(0018, 0050) Slice Thickness DS: ‘3.00000’  
(0028, 0030) Pixel Spacing DS: [‘0.597656’, ‘0.597656’]  
tag which should be the only tag that contains relevant information.

The standard NEMA image I checked with is from ftp://medical.nema.org/MEDICAL/Dicom/Multiframe/CT/

Thanks for your help anyway. 🙂 Maybe I should try and convert this into separate images first!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 8, 2017, 9:34pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/9 "2017-06-08T21:34:56Z")

</div>

Understood - it’s always toughest to debug dicom files that can’t be shared.

Since it looks like you know your way around the header with pydicom you should be able to easily generate a basic nrrd file. You can probably even make a .nhdr that is just a few lines of ascii and points to the raw data in the original dicom file.

good luck

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 9, 2017, 1:50pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/10 "2017-06-09T13:50:56Z")

</div>

> [@Shilpa\_Ananth](#):
>
> tag in my file does not have image orientation under the plane orientation sequence. My file has it just under all the per-frame functional groups

It is a known issue with the datasets produced by some vendors, and the ITK reader is not robust enough to look for these attributes in the per-frame FG(s!) when they are missing in the shared FG.

---

<div class="post-metadata">

**Author:** ![Shilpa\_Ananth](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Shilpa\_Ananth](https://discourse.slicer.org/u/Shilpa_Ananth)\
**Post date:** [June 9, 2017, 1:57pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/11 "2017-06-09T13:57:54Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/8/a80b8a6b6ea24a4c9aad9a61440b3094f6b64700.png)

I did try moving it to the shared functional groups too. No luck.

Thanks Steve and Andrey!

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [June 9, 2017, 2:01pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/12 "2017-06-09T14:01:01Z")

</div>

How did you move it?

Does it pass the [validator](http://www.dclunie.com/dicom3tools/dciodvfy.html) after you modified the dataset?

---

<div class="post-metadata">

**Author:** ![evan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/evan/32/4953_2.png) [@evan](https://discourse.slicer.org/u/evan)\
**Post date:** [September 24, 2019, 4:33pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/13 "2019-09-24T16:33:43Z")

</div>

I have been experiencing this DICOM spacing & thickness error recently on quite a few DICOM sets.

The files have the following tags in metadata:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0a726d9e28e0168d842aa4c312f9421081a9c7d9.png)  
On load the error `Irregular volume geometry detected (maximum error of 931.5 mm is above tolerance threshold of 0.001 mm)` is displayed. The Volumes module shows the default spacing (1mm, 1mm, 1mm) and I must manually enter the correct values. Like @Shilpa_Ananth I am also looking to integrate this into another process so manual entry is not ideal. I did test **Acquisition geometry regularization** in _Application Settings_\>_DICOM_, which does fix visualization in the slicer viewer. However, this created resolution errors when performing transformations on the volume.

Here is a faulting [anonymized DICOM set](https://uwoca-my.sharepoint.com/:u:/g/personal/esimps27_uwo_ca/EdKwNKrGv-NLg_mJU-pFgEABQMqUyaXUD-H0gQpf67oLXw?e=ZjkjJW) to test.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 24, 2019, 6:26pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/14 "2019-09-24T18:26:31Z")

</div>

Hi @evan -

Thanks for sharing the data and describing what you see. I can replicate the issue with your data. This happens when the underlying ITK reader cannot interpret your data as a proper volume with equal spacing in all axes. This can happen if there are missing slices or it can happen if the slice ordering is not consistent (SliceThickness and SpacingBetweenSlices are not used for this, only the per-slice ImagePositionPatient and ImageOrientationPatient). In this data there must be some issue that ITK doesn’t deal with or else the data is just wrong (I didn’t look at your data closely to see what the issue is here).

The [`Acquisition geometry regularization`](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L555-L718) code detects this error and can correct for it when enabled. It creates a non-linear transform to put the slices back in the correct places as defined by the position and orientation.

You can use the `Harden Transform` button in the Transforms module to apply the non-linear regularization transform to the data and then you can use it for other operations.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/9/59a0009b8cd529691aa3ff9247975b58f404ceb5.png)

---

<div class="post-metadata">

**Author:** ![evan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/evan/32/4953_2.png) [@evan](https://discourse.slicer.org/u/evan)\
**Post date:** [September 27, 2019, 7:52pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/15 "2019-09-27T19:52:00Z")

</div>

Hi @pieper, thanks for the response and useful information!

I iterated through the slices and couldn’t seem to find a missing slice or order inconsistency.

I tried the Acquisition geometry regularization again with Harden Transform. Here is an example of the transform resolution I’m seeing.

Before harden:

 ![Without%20harden](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/8/b808793132a81928172e831ae7eaad0dae9b7f35.png)  
After harden:  
 ![Hardened](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/5/b5319749ef4ee4f5a605f78c0b6d67a5c5a9d00d.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 27, 2019, 8:39pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/16 "2019-09-27T20:39:26Z")

</div>

Looks like progress - you can control the resampling resolution using other methods: [https://www.slicer.org/wiki/Documentation/4.10/Modules/Resampling](https://www.slicer.org/wiki/Documentation/4.10/Modules/Resampling)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 27, 2019, 11:45pm UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/18 "2019-09-27T23:45:13Z")

</div>

It’s a complex process actually, so the only real way to know is to look at the source code. The best short answer is it uses the `ImagePositionPatient` tags of the slices in a volume together with `PixelSpacing`.

At the center of things is some code that [applies a number of heuristics](https://github.com/InsightSoftwareConsortium/ITK/blob/970e7fa9ce42f9d3da78c47213a320abc382d613/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L483). I’m not a huge fan of this code, but it was developed by people who had access to file types that are not available for testing.

---

<div class="post-metadata">

**Author:** ![issakomi](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@issakomi](https://discourse.slicer.org/u/issakomi)\
**Post date:** [October 1, 2019, 1:29am UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/22 "2019-10-01T01:29:58Z")

</div>

> I’m not a huge fan of this code

BTW, [this switch](https://github.com/InsightSoftwareConsortium/ITK/blob/970e7fa9ce42f9d3da78c47213a320abc382d613/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L514) is useless, forced Tag is ([0028,0030](https://github.com/InsightSoftwareConsortium/ITK/blob/970e7fa9ce42f9d3da78c47213a320abc382d613/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L506)), so VR is always _DS_ in [dictionary](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDefaultDicts.cxx), this switch was simply copy/pasted, [s. here](https://github.com/InsightSoftwareConsortium/ITK/blob/970e7fa9ce42f9d3da78c47213a320abc382d613/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx#L1321) and [dictionary lookup above](https://github.com/InsightSoftwareConsortium/ITK/blob/970e7fa9ce42f9d3da78c47213a320abc382d613/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L510) is useless too, it is loop.

---

<div class="post-metadata">

**Author:** ![issakomi](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@issakomi](https://discourse.slicer.org/u/issakomi)\
**Post date:** [October 1, 2019, 11:48am UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/23 "2019-10-01T11:48:14Z")

</div>

[PR](https://github.com/InsightSoftwareConsortium/ITK/pull/1280)

---

<div class="post-metadata">

**Author:** ![Juicy](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juicy](https://discourse.slicer.org/u/Juicy)\
**Post date:** [October 10, 2019, 6:53am UTC](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453/24 "2019-10-10T06:53:52Z")

</div>

Hi @pieper ,

Do you mind briefly explaining what Apply regularization transform actually does? I have used it to fix gantry tilt issues and to fix issues like the one described above, but I don’t understand what it is.

Also I notice that it is not enabled by default. It seems to do a good job of fixing errors so is there any reason why I shouldn’t leave this setting enabled all the time?

Thanks for your contributions to Slicer!

[Next page](https://discourse.slicer.org/t/slicer-loads-wrong-image-spacing/453.md?page=2)
