# How can I convert an rtstruct to an nrrd

**URL:** <https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539>\
**Category:** Support\
**Created:** [June 20, 2017, 1:48pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539 "2017-06-20T13:48:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 20, 2017, 1:48pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/1 "2017-06-20T13:48:27Z")

</div>

Operating system: Windows  
Slicer version:4.6.2  
Expected behavior:  
Actual behavior:

---

<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 20, 2017, 2:19pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/2 "2017-06-20T14:19:34Z")

</div>

In Segmentations module change Master representation to binary labelmap (click `Make master` button in the `Binary labelmap` row in Representations section) then save the scene. Structure sets may overlap, therefore the nrrd file will be a 4-dimensional volume, each segment is stored in a separate 3D subvolume.

Use latest nightly build, it’s stable and contains many fixes and improvements.

---

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 20, 2017, 2:38pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/3 "2017-06-20T14:38:34Z")

</div>

Thank you for the help

---

<div class="post-metadata">

**Author:** ![gcsharp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gcsharp/32/863_2.png) [@gcsharp](https://discourse.slicer.org/u/gcsharp)\
**Post date:** [June 20, 2017, 3:02pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/4 "2017-06-20T15:02:41Z")

</div>

Andras, is there a way to create a separate 3D volume file for each segment?

The information in this e-mail is intended only for the person to whom it is  
addressed. If you believe this e-mail was sent to you in error and the e-mail  
contains patient information, please contact the Partners Compliance HelpLine at  
[http://www.partners.org/complianceline](http://www.partners.org/complianceline) . If the e-mail was sent to you in error  
but does not contain patient information, please contact the sender and properly  
dispose of the e-mail.

---

<div class="post-metadata">

**Author:** ![Josiah\_McAllister](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@Josiah\_McAllister](https://discourse.slicer.org/u/Josiah_McAllister)\
**Post date:** [June 20, 2017, 3:17pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/5 "2017-06-20T15:17:09Z")

</div>

Andras, is there a way to get my segmentation and my image to both be the  
same dimensions?

---

<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 20, 2017, 3:19pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/6 "2017-06-20T15:19:19Z")

</div>

> [@gcsharp](#):
>
> Andras, is there a way to create a separate 3D volume file for each segment?

This option is not easily available for the user. You can load the .seg.nrrd file as a volume sequence if you choose “Volume Sequence” in the Add data dialog and then save it, but by default it is saved again as a 4D sequence. You would need to change the default storage node to vtkMRMLSequenceStorageNode to save as a zip file that contains each volume as a separate file.

ITK and VTK can both read volume sequences from 4D files, we also have a Matlab reader/writer that supports 4D volumes, so we never needed them as separate volumes.

---

<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 20, 2017, 3:25pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/7 "2017-06-20T15:25:41Z")

</div>

> [@Josiah\_McAllister](#):
>
> is there a way to get my segmentation and my image to both be the  
> same dimensions?

Segmentation will have the same origin, axis direction, and spacing as the input image, but extent usually does not match the input image.

Note that the nrrd header contains SegmentN\_Extent:=imin imax jmin jmax kmin kmax field that you can use to efficiently extract only that part of the 3D volume where your particular segment is. You can copy that extent into a larger volume that matches extent of your image.

---

<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 20, 2017, 8:12pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/8 "2017-06-20T20:12:53Z")

</div>

2 posts were split to a new topic: [Convert image and segmentation to DICOM](https://discourse.slicer.org/t/convert-image-and-segmentation-to-dicom/543)

---

<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 21, 2017, 4:18pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/9 "2017-06-21T16:18:47Z")

</div>

A post was merged into an existing topic: [Convert image and segmentation to DICOM](https://discourse.slicer.org/t/convert-image-and-segmentation-to-dicom/543)

---

<div class="post-metadata">

**Author:** ![mete\_naz](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@mete\_naz](https://discourse.slicer.org/u/mete_naz)\
**Post date:** [March 5, 2018, 9:21pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/10 "2018-03-05T21:21:33Z")

</div>

Andras,

Is there a way to share the code with us? I have been trying to figure out how to read my segmented nrrd file however i has been giving me a lot of issues so I couldn’t… I would appreciate if you could possible share your code with me.

Thanks!

---

<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:** [March 5, 2018, 11:06pm UTC](https://discourse.slicer.org/t/how-can-i-convert-an-rtstruct-to-an-nrrd/539/11 "2018-03-05T23:06:09Z")

</div>

Segmentation is a 4D image in standard nrrd format. You can read it using either VTK or ITK nrrd reader or any nrrd reader that supports 4D volumes. See for example how Slicer reads it: [https://github.com/Slicer/Slicer/blob/0ab294089b4827fea3272417a23c321d57e391b4/Libs/MRML/Core/vtkMRMLSegmentationStorageNode.cxx#L290](https://github.com/Slicer/Slicer/blob/0ab294089b4827fea3272417a23c321d57e391b4/Libs/MRML/Core/vtkMRMLSegmentationStorageNode.cxx#L290)
