# DICOM Enhanced CT with GDCM\_IO

**URL:** https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402
**Category:** Algorithms
**Created:** [October 9, 2022, 10:17pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402 "2022-10-09T22:17:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rfrank](https://discourse.itk.org/user_avatar/discourse.itk.org/rfrank/32/2977_2.png) [@rfrank](https://discourse.itk.org/u/rfrank)
#### Post date: [October 9, 2022, 10:17pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/1 "2022-10-09T22:17:25Z")

</div>

Hi

I’m working on an existing code base that uses ITK/Gdcm ITK 4.12

I have a Toshiba ct multi frame.

ITK is returning direction cosines

1 0 0 0 1 0 0 0 -1

And I need to swap the z axis and reset the direction cosines to identity to get the slices so that the software can access the voxels correctly  
the software prefers LPS → ijk

Ok that’s fine, but I need to document this for a report and I’m trying to understand the code where this is handled.

It seems that in gdcmImageHelper ComputeZSpacingFromIPP() the spacing for Z is computed negative.

Since its negative, later in

itkImageFileReader.hxx

// Spacing is expected to be greater than 0

// If negative, flip image direction along this axis.

it sets the direction cosine to -1 for the z access. But it doesn’t flip the voxels.

I’m wondering who’s “correct” here?

If spacing is a “distance”, it shouldn’t be negative I would think ?.

The only place I see negative spacing i [https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect\_C.8.4.15.htmls](https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.4.15.htmls)

That would lead me to think it’s a defect in GDCM.

Let me know what the consensus is on this. I just need to document the behavior.

Thanks!

Rick

---

<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: [October 10, 2022, 2:00pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/2 "2022-10-10T14:00:57Z")

</div>

@mathieu.malaterre and @mihail.isakov might provide explanations.

---

<div class="post-metadata">

### Author: ![mathieu.malaterre](https://discourse.itk.org/user_avatar/discourse.itk.org/mathieu.malaterre/32/205_2.png) [@mathieu.malaterre](https://discourse.itk.org/u/mathieu.malaterre)
#### Post date: [October 10, 2022, 2:25pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/3 "2022-10-10T14:25:21Z")

</div>

As far as I remember ITK does handle “negative” spacing quite well. This was a trick to load an Enhanced format in the file order. The fact that ITK tolerate negative spacing is out of scope with regards to DICOM standard.

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [October 10, 2022, 4:16pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/4 "2022-10-10T16:16:05Z")

</div>

You may try [dcm2niix](https://github.com/rordenlab/dcm2niix) (maybe prefer Nrrd output), dcm2niix process every frame in per frame group and is tolerant even to randomly ordered slices in enhanced IODs, s. this [discussion](https://github.com/rordenlab/dcm2niix/issues/372) with D. Clunie examples. With ITK/GDCM if the volume is not uniform and frames are not sorted ascending by IPP/IOP there may be issues. You can also load such files in Slicer using dcm2niix plugin. Also you can view most multi-frame files in the [program](https://github.com/AlizaMedicalImaging/AlizaMS), incl. non-uniform, 3D+, etc.

P.S. If you export to Nifti or Nrrd with dcm2niix and load into ITK, the orientation may be not the original one (possible different reference spaces), but should be correct, AFAIK.

Edit:

> [@rfrank](#):
>
> The only place I see negative spacing i [https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect\_C.8.4.15.htmls](https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.4.15.htmls)

Link doesn’t work, corrected link is  
[https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect\_C.8.4.15.html](https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.4.15.html)

I also don’t know other IOD where negative spacing is allowed.

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [October 19, 2022, 10:17pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/6 "2022-10-19T22:17:30Z")

</div>

Generally ITK doesn’t tolerate negative spacing in [SetSpacing](https://github.com/InsightSoftwareConsortium/ITK/blob/8e34f1078e13b4ae39d8aaa600ff936a9a3050bb/Modules/Core/Common/include/itkImageBase.hxx#L83) if _legacy_ code is removed, BTW.

> the code where this is handled.

But in the file reader it is done before _SetSpacing_ here: [itkImageFileReader.hxx](https://github.com/InsightSoftwareConsortium/ITK/blob/8e34f1078e13b4ae39d8aaa600ff936a9a3050bb/Modules/IO/ImageBase/include/itkImageFileReader.hxx#L219)

---

<div class="post-metadata">

### Author: ![rfrank](https://discourse.itk.org/user_avatar/discourse.itk.org/rfrank/32/2977_2.png) [@rfrank](https://discourse.itk.org/u/rfrank)
#### Post date: [October 20, 2022, 1:15pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/7 "2022-10-20T13:15:23Z")

</div>

Thanks

I’m looking to add the capability of reading the enhanced CT to this code base.

I’m reading the spec, etc.

So looking at the tags in the files, I have a 2 file series- 2 files with the same series uid. There are in the order of 300 images in each file based on number of frames. So, I assume there’s an “index” located somewhere in these files. The way I envision it:

Read image position patient tags  
Sort  
Read Other meta data  
Read images

But where is this “index”? In what tags or tags is the structure of the file “described”? I don’t know where to start ¯\_(ツ)\_/¯

With a file by file series, the “index” is the file system, but I need the same “index” for these files…

Thanks  
Rick

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [October 21, 2022, 10:31am UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/8 "2022-10-21T10:31:40Z")

</div>

> [@rfrank](#):
>
> But where is this “index”? In what tags or tags is the structure of the file “described”? I don’t know where to start

A structure of [Enhanced CT Image](https://dicom.innolitics.com/ciods/enhanced-ct-image) instance is described in [Multi-frame Dimension Module](https://dicom.innolitics.com/ciods/enhanced-ct-image/multi-frame-dimension) and [Frame Content Sequence](https://dicom.innolitics.com/ciods/enhanced-ct-image/enhanced-ct-image-multi-frame-functional-groups/52009230/00209111) in _Per-frame Functional Groups Sequence_. The module may be absent in a _Legacy Converted_ instance. There is also no guarantee that e.g. _Stack ID_ and _In-Stack Position Number_ order will be the same as the result of ascending IPP/IOP sorting of frames of the stack. All this is very difficult stuff unfortunately.  
Not sure how to sort series of enhanced instances, maybe _Instance Number_, Acquisition or other time.

---

<div class="post-metadata">

### Author: ![rfrank](https://discourse.itk.org/user_avatar/discourse.itk.org/rfrank/32/2977_2.png) [@rfrank](https://discourse.itk.org/u/rfrank)
#### Post date: [October 21, 2022, 3:48pm UTC](https://discourse.itk.org/t/dicom-enhanced-ct-with-gdcm-io/5402/9 "2022-10-21T15:48:40Z")

</div>

Thanks

It seems like the images I have are best described by

> **[Per-frame Functional Groups Sequence Attribute – DICOM Standard Browser](https://dicom.innolitics.com/ciods/multi-frame-grayscale-byte-sc-image/multi-frame-grayscale-byte-sc-image-multi-frame-functional-groups/52009230)**
>
> Sequence that contains the Functional Group Sequence Attributes corresponding to each frame of the Multi-frame Image. The first Item corresponds with the first frame, and so on.

This tag exists in the files I’m working with, but it’s a 1C
