# Export DICOM-SEG data

**URL:** <https://discourse.slicer.org/t/export-dicom-seg-data/21636>\
**Category:** Support\
**Tags:** segmentation, dicom\
**Created:** [January 26, 2022, 4:20pm UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636 "2022-01-26T16:20:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Johannes](https://discourse.slicer.org/u/Johannes)\
**Post date:** [January 26, 2022, 4:20pm UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636/1 "2022-01-26T16:20:23Z")

</div>

Hi everyone,

I cannot export DICOM SEG files from anonymized DICOM files.  
It works without any problems with DICOM objects that have not been anonymized.

As an example, this dataset from the internet can be used to reproduce the problem.

- [GitHub - datalad/example-dicom-structural: Example DICOM dataset for a T1w image acquisition](https://github.com/datalad/example-dicom-structural)

I get the error message:

> Segmentation object export failed.  
> Completed with errors:  
> Convert ITK image(s) into DICOM Segmentation Image standard error  
> Condition failed: Maximum VR length violated in /work Stable/S-1E-b/DCMQI/libsrc/ImageSEGConverter.cpp:112  
> Fatal error encountered.

Which Dicom field causes problems here?

---

<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:** [January 26, 2022, 10:42pm UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636/2 "2022-01-26T22:42:12Z")

</div>

In particular case maybe _DS_ fields cause the problem, not 100% sure. S. [dciodvfy](https://www.dclunie.com/dicom3tools/dciodvfy.html). Completely clean files are seldom, there are very often warnings, BTW.

`dciodvfy /home/r/Downloads/example-dicom-structural-master/dicoms/N2D_0001.dcm`

```auto
Warning - Value dubious for this VR - (0x0010,0x0010) PN Patient's Name PN [1] = <Jane_Doe> - Retired Person Name form
Error - Value invalid for this VR - (0x0010,0x1010) AS Patient's Age AS [1] = <42> - Length invalid for this VR = 2, expected == 4
Error - Value invalid for this VR - (0x0018,0x0050) DS Slice Thickness DS [1] = <0.666666686534882> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0018,0x0088) DS Spacing Between Slices DS [1] = <0.666666686534882> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0032) DS Image Position (Patient) DS [1] = <-91.4495864331908> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0032) DS Image Position (Patient) DS [3] = <-142.505487236053> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0037) DS Image Orientation (Patient) DS [1] = <0.999032176441525> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0037) DS Image Orientation (Patient) DS [2] = <-0.0217883751691557> - Length invalid for this VR = 19, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0037) DS Image Orientation (Patient) DS [3] = <0.0382096472372976> - Length invalid for this VR = 18, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0037) DS Image Orientation (Patient) DS [4] = <0.026519476938784> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0020,0x0037) DS Image Orientation (Patient) DS [5] = <0.991413870277297> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0028,0x0030) DS Pixel Spacing DS [1] = <0.666666686534882> - Length invalid for this VR = 17, expected <= 16
Error - Value invalid for this VR - (0x0028,0x0030) DS Pixel Spacing DS [2] = <0.699987828731537> - Length invalid for this VR = 17, expected <= 16
Error - Dicom dataset contains invalid data values for Value Representations
Warning - Retired attribute - (0x0010,0x1000) LO Other Patient IDs 
Warning - Dicom dataset contains retired attributes
MRImage
Error - Missing attribute Type 2C Conditional Element=<Laterality> Module=<GeneralSeries>
Error - Missing attribute Type 2C Conditional Element=<PatientPosition> Module=<GeneralSeries>
Error - Missing attribute Type 2 Required Element=<PositionReferenceIndicator> Module=<FrameOfReference>
Error - A value is required for value 3 in MR Images - attribute <ImageType>
Error - Missing attribute Type 1 Required Element=<ScanningSequence> Module=<MRImage>
Error - Missing attribute Type 1 Required Element=<SequenceVariant> Module=<MRImage>
Error - Missing attribute Type 2 Required Element=<ScanOptions> Module=<MRImage>
Error - Missing attribute Type 2 Required Element=<MRAcquisitionType> Module=<MRImage>
Error - Missing attribute Type 2C Conditional Element=<RepetitionTime> Module=<MRImage>
Error - Missing attribute Type 2 Required Element=<EchoTime> Module=<MRImage>
Error - Missing attribute Type 2 Required Element=<EchoTrainLength> Module=<MRImage>
Warning - Attribute is not present in standard DICOM IOD - (0x0010,0x1000) LO Other Patient IDs 
Warning - Attribute is not present in standard DICOM IOD - (0x0028,0x1052) DS Rescale Intercept 
Warning - Attribute is not present in standard DICOM IOD - (0x0028,0x1053) DS Rescale Slope 
Warning - Attribute is not present in standard DICOM IOD - (0x0028,0x1054) LO Rescale Type 
Warning - Dicom dataset contains attributes not present in standard DICOM IOD - this is a Standard Extended SOP Class

```

---

<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:** [January 27, 2022, 5:06am UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636/3 "2022-01-27T05:06:55Z")

</div>

Many errors are tolerated, but the geometry (origin, spacing, axis directions) are stored in invalid decimal string (DS) values that the DICOM writer cannot reproduce. So, it is not possible to use this messed up DICOM image as a reference image for a DICOM segmentation object.

I would recommend to contact the maintainers of the [https://github.com/datalad/example-dicom-structural](https://github.com/datalad/example-dicom-structural) repository about the issue and see if they are willing to fix up the data set. At least they should describe these issues in the repository. Probably the culprit is the `nifti2dicom` utility that they used. The problem should be reported to the maintainers of `nifti2dicom`, too.

In the meantime, you can create a valid DICOM volume by loading the invalid DICOM into Slicer (it will tolerate it), then export it into DICOM within Slicer. Then load that DICOM volume and use that as master volume for the segmentation.

---

<div class="post-metadata">

**Author:** ![Johannes](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Johannes](https://discourse.slicer.org/u/Johannes)\
**Post date:** [January 27, 2022, 12:06pm UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636/4 "2022-01-27T12:06:48Z")

</div>

**Thank you so much!!!.** I will create a corresponding report.

The problem seems to occur with many data sets from the Internet. I couldn’t find one that would allow me to generate DICOM SEG files. Maybe because most of them created by nifti2dcm.

**Regardless, the workaround you suggested works fine!**

---

<div class="post-metadata">

**Author:** ![lennart81](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lennart81/32/79042_2.png) [@lennart81](https://discourse.slicer.org/u/lennart81)\
**Post date:** [January 23, 2025, 11:33am UTC](https://discourse.slicer.org/t/export-dicom-seg-data/21636/5 "2025-01-23T11:33:16Z")

</div>

Thanks @lassoan - this fix helped me a lot in getting DICOM seg files exported
