# Export segmentation to Nifti messes up labels

**URL:** https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196
**Category:** Support
**Tags:** segmentation
**Created:** [April 26, 2017, 2:13pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196 "2017-04-26T14:13:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@Yannick](https://discourse.slicer.org/u/Yannick)
#### Post date: [April 26, 2017, 2:13pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/1 "2017-04-26T14:13:51Z")

</div>

Hello,

I have been labelling 3D volumes for a while now, but I always have troubles to export into a format which can be easily read by ImageJ or Fiji. usually, one label is missing and others have incorrect id. Please tell me the recommended way.

The problem:  
1- Load a 3D volume (I use Analyze format)  
2- Go to the new Segment Editor, create at least 5 segments and draw over the volume. No problem there.  
3- The segmentation can be saved as “Segmentation.seg.nrrd” or “Segmentation.nrrd” only.  
How do I export to something more usual (Analyze / Nifti are more familiar to me) ? The other formats are not available in the list there.

This doesn’t work:  
4- Open a new 3D Slicer window and drop the “Segmentation.nrrd” into it (load as a Volume). The funny thing is I do see the segmented regions. That’s what I want to export.  
5- There, I can choose other formats, such as Analywe (.hdr) or Nifti (.nii). This creates a volume on the disk.  
6- ImageJ loads a volume which has at least 5 channels, but channel 4 is gone and the channels from 5 and beyond have a index decreased by 1. Is there any explanation to this ?

Thanks for the feedback and explanations on the correct export sequence.

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [April 26, 2017, 2:22pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/2 "2017-04-26T14:22:57Z")

</div>

For import in to ImageJ/Fiji, why not use NRRD? ImageJ/FIJI had decent support for NRRD last time I used it.

I’m not sure about the Nifti part of the question – do you have any documentation of what format your other software considers as a “Nifti labelmap”? It might be helpful to link a sample dataset.

---

<div class="post-metadata">

### Author: ![Yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@Yannick](https://discourse.slicer.org/u/Yannick)
#### Post date: [April 26, 2017, 3:39pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/3 "2017-04-26T15:39:03Z")

</div>

Thanks for the reply.

I must be missing something obvious, but I don’t see how to do it:

- Fiji opens NRRD using the BioFormat plugin. I’ve updated it today.
  - When I throw Segmentation.nrrd on it, it complains that it doesn’t work for more than 3 dimensions.

- ImageJ 1.49v and 1.50 only open a text editor when I throw the NRRD file.

For now, I assume there is no tool which converts NRRD to Nifti in dimensions higher than 3.  
(The Editor in Slicer, seems to create one dimension for each Segment and store binary values for each segment. This allows a voxel to belong to multiple Segments simultaneously)

From a different application, there are reports that conversion using CMTK doesn’t allow more than 3 dimensions ([link](https://www.nitrc.org/forum/forum.php?thread_id=3573&forum_id=857)).

I’ll be working on a small dataset tomorrow.

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [April 26, 2017, 4:02pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/4 "2017-04-26T16:02:50Z")

</div>

If you are using the segment editor, you need to export your segments as label maps, I think. You can use the segmentation module to do that.  
m

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)
#### Post date: [April 26, 2017, 4:03pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/5 "2017-04-26T16:03:56Z")

</div>

The first thing to figure out is what the Nifti file should look like. What do you consider to be a “more usual” analyze/nifti holding a segmentation? Is it supposed to be a 4d volume, a bitmask, or something else. (if it’s supposed to be a bitmask, try converting the segmentation to a labelmap and export that as nii).

For NRRD, have you tried SCIFIO?

---

<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: [April 26, 2017, 4:05pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/6 "2017-04-26T16:05:29Z")

</div>

If your labels are not overlapping then you can convert the segmentation into a labelmap (simple 3D volume, each segment has a different voxel value):

- Go to Data module (if you don’t use the latest nightly: Subject Hierarchy module)
- Right-click on the segmentation node, choose “Export visible segments to binary labelmap”
- Save the generated labelmap to file

---

<div class="post-metadata">

### Author: ![Yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@Yannick](https://discourse.slicer.org/u/Yannick)
#### Post date: [April 27, 2017, 8:33am UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/7 "2017-04-27T08:33:08Z")

</div>

Thanks to @lassoan, @muratmaga (and the others)

You are all correct: I need to export into a labalmap and I didn’t know this even existed.  
I’m using Slicer v4.6.2 and here are the operations I had to do:

- Module Segmentation, item “copy/move segment (import/export)”
  - Click icon to add a labelmap volume to the scene
  - Select all segments holding the shift key and press the “+\>” button to transfer them to the labelmap

- Save the project, Fiji can open the new Segment.nrrd without problem.

I was missing this step to convert all the binary segmentations into a labelmap.  
You saved my day. 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: [April 27, 2017, 12:15pm UTC](https://discourse.slicer.org/t/export-segmentation-to-nifti-messes-up-labels/196/8 "2017-04-27T12:15:58Z")

</div>

I would strongly recommend to use latest nightly version of Slicer. It has lots of fixes and improvements compared to the last stable version.
