# Trying to export nrrd file segmentation to DICOM

**URL:** <https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375>\
**Category:** Support\
**Tags:** segmentation, dicom\
**Created:** [September 7, 2020, 2:29pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375 "2020-09-07T14:29:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_T](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gabriel_t/32/4222_2.png) [@Gabriel\_T](https://discourse.slicer.org/u/Gabriel_T)\
**Post date:** [September 7, 2020, 2:29pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/1 "2020-09-07T14:29:13Z")

</div>

I am using version 4.11.0-2020-08-09  
I have converted some segmentation from numpy format to nrrd, I also converted my CT volume from numpy to nrrd, I am able to load them fine in slicer 3d, but I wanted to convert this to dicom format so that the segmentations as well as the CT can be read by dicom viewers.

 ![correct_loading](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8a1280f89fcff032f379568ab41c8146a1bdcacd.jpeg)  
Seems like RTStruct is the only way or are there better ways to do this ?  
I tried to convert to dicom RTSTruct by following the steps below

> [@Convert image and segmentation to DICOM](https://discourse.slicer.org/t/convert-image-and-segmentation-to-dicom/543/2):
>
> You are trying to convert nrrd files into a RT Structure Set using 3D Slicer? By coincidence, I documented this procedure earlier today. Load all images. At time of load, click “Labelmap” checkbox for each structure Go to Segmentation module For “Active segmentation”, choose “Create new segmentation” For each structure, repeat: 4a) In “Export/Import segments”, choose structure, and import as labelmap Click on one of the segments, and then click “Edit selected” Set the “Master volume” to your…

But after I convert to RTStruct I get images that dont display any contours.

 ![radiant_view](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/c/9c0aacfa443ff795e43ad7312b4165746e70782d.jpeg)  
Is there something that I am doing wrong ?

---

<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:** [September 7, 2020, 2:53pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/2 "2020-09-07T14:53:01Z")

</div>

The RT structure set does not even show up in the series list in the screenshot. What viewer are you trying to use?

I would recommend to use DICOM Segmentation Object (instead of the archaic and very limited RT structure set). This option shows up after you install Quantitative reporting extension. For future reference, see list of supported DICOM information objects [here](https://slicer.readthedocs.io/en/latest/user_guide/supported_data_formats.html).

---

<div class="post-metadata">

**Author:** ![Gabriel\_T](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gabriel_t/32/4222_2.png) [@Gabriel\_T](https://discourse.slicer.org/u/Gabriel_T)\
**Post date:** [September 7, 2020, 3:15pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/3 "2020-09-07T15:15:05Z")

</div>

Thank you for the suggestion,

I was using RadiAnt DICOM Viewer to view the folder containing the exported dicom files and the RTstruct but for some reason the RTStruct doesnt show up.

When I try to export to DICOM Segmentation Object using the Quantitative reporting extension I get two errors. I had loaded the segmentation nrrd as label map and the primary CT volume is also an nrrd object.

Error 1 -  
Could not retrieve DICOM tag value from input parameter None  
Error 2 -  
Traceback (most recent call last):  
File “”, line 2, in   
File “C:/Users/gabri/AppData/Roaming/NA-MIC/Extensions-29335/QuantitativeReporting/lib/Slicer-4.11/qt-scripted-modules/DICOMSegmentationPlugin.py”, line 350, in export  
exporter.export(exportable.directory, segFileName, metadata)  
File “C:/Users/gabri/AppData/Roaming/NA-MIC/Extensions-29335/QuantitativeReporting/lib/Slicer-4.11/qt-scripted-modules/DICOMSegmentationPlugin.py”, line 499, in export  
absolutePaths=True)  
File “C:/Users/gabri/AppData/Roaming/NA-MIC/Extensions-29335/QuantitativeReporting/lib/Slicer-4.11/qt-scripted-modules/DICOMSegmentationPlugin.py”, line 575, in getDICOMFileList  
instanceUIDs = volumeNode.GetAttribute(attributeName)  
AttributeError: ‘NoneType’ object has no attribute ‘GetAttribute’

---

<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:** [September 7, 2020, 3:17pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/4 "2020-09-07T15:17:14Z")

</div>

You need to set the referenced image before you can export a DICOM Segmentation Object. To do this, you can go to Segment Editor module and choose the referenced image as Master volume. We’ll update the exporter to make this requirement more clear.

---

<div class="post-metadata">

**Author:** ![Gabriel\_T](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gabriel_t/32/4222_2.png) [@Gabriel\_T](https://discourse.slicer.org/u/Gabriel_T)\
**Post date:** [September 7, 2020, 3:27pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/5 "2020-09-07T15:27:18Z")

</div>

I had selected the CT volume as the master volume in segment editor

 ![segmenteditor](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/6/466f791b1763d34f1534de0e92888593a47df8f1.png)  
Below is the subject hierarchy, is this correct ?  
 ![hierarchy](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/2/12853f71327b14034897e94af0267ae0198a02da.png)  
But when I export this using DICOM seg it gives the same two errors

---

<div class="post-metadata">

**Author:** ![adamaji](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamaji/32/12772_2.png) [@adamaji](https://discourse.slicer.org/u/adamaji)\
**Post date:** [November 29, 2021, 2:38pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/6 "2021-11-29T14:38:31Z")

</div>

Sorry to bring back this old issue, but was there any success here? Was trying to do something similar (export seg from NRRD to DICOM) without success.

Following [DICOM — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/user_guide/modules/dicom.html#export-data-from-the-scene-to-dicom-database) and [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#export-a-segmentation-to-dicom-segmentation-object) do not work – even when the seg has a reference volume set manually, there are some missing DICOM tags/node attributes which prevent the export from proceeding.

I assume since [Slicer SEG export is failing when reference volume is not DICOM · Issue #247 · QIICR/QuantitativeReporting · GitHub](https://github.com/QIICR/QuantitativeReporting/issues/247) is still open without comment there hasn’t been any movement in this regard?

---

<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:** [November 29, 2021, 4:05pm UTC](https://discourse.slicer.org/t/trying-to-export-nrrd-file-segmentation-to-dicom/13375/7 "2021-11-29T16:05:20Z")

</div>

DICOM Segmentation Object export works well, it just complicated because of required cross-references between DICOM files.

If you use a recent Slicer Preview Release then you will get detailed error message about what steps were missed.

If you don’t export to existing DICOM studies but you make up new ones then you need to create the patients, studies, image series first and then associate this DICOM volume with the existing segmentation:

- Export the volume to the DICOM database and then load the volume from the DICOM database.
- Drag-and-drop the segmentation under the loaded DICOM volume’s study.
- Go to Segment Editor and set the loaded DICOM volume as source geometry (by clicking the Specify geometry button and selecting the loaded DICOM volume as “source geometry”)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/b/fbcf842ba0f6aa920ed742b569d0079a3e1a38f3.png)

After this, you can export the segmentation as DICOM segmentation object by right-clicking on the segmentation node in Data module.

You can find a script here that fully automates this process (even takes care of assigning DICOM terminologies, in case someone is just converting plain labelmaps and not segmentation nodes): [GitHub - lassoan/LabelmapToDICOMSeg: Script for converting labelmap volumes to DICOM segmentation objects](https://github.com/lassoan/LabelmapToDICOMSeg)
