# New segment for every colour

**URL:** <https://discourse.slicer.org/t/new-segment-for-every-colour/7653>\
**Category:** Support\
**Created:** [July 18, 2019, 11:56am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653 "2019-07-18T11:56:06Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![the3dslicerdude](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@the3dslicerdude](https://discourse.slicer.org/u/the3dslicerdude)\
**Post date:** [July 18, 2019, 11:56am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/1 "2019-07-18T11:56:07Z")

</div>

Hi there

I have a 16bit raw image stack of a segmentation ‘so it doesn’t have a crazy amount of colors in the image itself’. Is there a way in slicer to generate a segment for every existing color in the image using the segment editor? Hopefully slicer can handle a fairly large number of segments. Sorry if it sounds confusing

Any help would be appreciated

---

<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:** [July 18, 2019, 12:51pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/2 "2019-07-18T12:51:57Z")

</div>

It sounds like you have a labelmap volume (you have discrete values in the volume, each value corresponds to a certain structure). You can follow these instructions to load this image and import to segmentation:

> [@Save .nrrd file into STL file](https://discourse.slicer.org/t/save-nrrd-file-into-stl-file/4954/2):
>
> If your nrrd is binary (i.e. contains a segmentation) then you can load it as a labelmap (click Show Options in the load window and check LabelMap option). Then go to Data module, right-click the labelmap, select Convert labelmap to segmentation node. Then go to the Segmentations module, select the segmentation, go to the very bottom to the Export to files section, then select your options and click Export.

---

<div class="post-metadata">

**Author:** ![the3dslicerdude](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@the3dslicerdude](https://discourse.slicer.org/u/the3dslicerdude)\
**Post date:** [July 18, 2019, 1:00pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/3 "2019-07-18T13:00:20Z")

</div>

Thank you so much for the quick reply, I won’t be able to try this until tomorrow. Just one question in regards to your answer, will I be able to re-sample while using the method in the other thread

---

<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:** [July 18, 2019, 1:20pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/4 "2019-07-18T13:20:07Z")

</div>

Yes, you can crop and resample labelmap volumes the same way as scalar volumes, just make sure to use _nearest neighbor_ interpolator if you want to preserve original voxel values at the boundaries.

---

<div class="post-metadata">

**Author:** ![the3dslicerdude](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@the3dslicerdude](https://discourse.slicer.org/u/the3dslicerdude)\
**Post date:** [July 19, 2019, 3:17am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/5 "2019-07-19T03:17:44Z")

</div>

After trying this method with about 1/8th of the dataset, which is a 700mb nrrd file. It did work but took a very long time to compute and with the labels it uses about 98percent of my 16gigs of ram. I will try some other software packages but I feel like they will also be too resource heavy

---

<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:** [July 19, 2019, 3:24am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/6 "2019-07-19T03:24:36Z")

</div>

Currently, you can can probably edit up to about 30-50 segments at a time and move out other segments to another segmentation or labelmap. We are improving the segment editor to better support some neurosegmentation workflows which may involve a few hundred segments.

What kind of data do you work with? How many segments do you have? What is the volume size?

---

<div class="post-metadata">

**Author:** ![the3dslicerdude](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@the3dslicerdude](https://discourse.slicer.org/u/the3dslicerdude)\
**Post date:** [July 19, 2019, 3:30am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/7 "2019-07-19T03:30:04Z")

</div>

It is a micro-ct of a mammal and has I estimate it will have north of 200 segments if I was to load in the full dataset. Unfortunately I am interested in preserving as much detail as possible so reducing the quality isn’t really an option. Looking forward to future updates to the segment editor.

---

<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:** [July 19, 2019, 3:30am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/8 "2019-07-19T03:30:33Z")

</div>

What is the volume size?

---

<div class="post-metadata">

**Author:** ![the3dslicerdude](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@the3dslicerdude](https://discourse.slicer.org/u/the3dslicerdude)\
**Post date:** [July 19, 2019, 1:57pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/9 "2019-07-19T13:57:31Z")

</div>

Sorry I am not sure how to check that. However today I did try to do the same with the 1/8th data set using both Itk-snap and Mimics. I wasn’t able to find where to import a labelmap for mimics ‘it probably doesn’t have this functionality’, but with itk-snap I just clicked open segmentation and opened the nrrd and it imported and created the hundred or so masks within a few seconds, and also had almost no effect on the memory usage (to compare, slicer took about 5 minutes to generate the segments and used 98percent ram once they were imported). Itk also had a really nice export all segments into single vtk scene which didn’t create a file size too large. However the downside with Itk-snap is the mesh it created was not as nice and had holes that were larger than the ones in slicer. Since I am interested in mesh quality, I am leaning more towards slicer, however memory usage and calculation speed is an issue with lots of labels

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [July 19, 2019, 2:14pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/10 "2019-07-19T14:14:40Z")

</div>

> [@the3dslicerdude](#):
>
> Sorry I am not sure how to check that

If you keep your mouse cursor above the CT in the Data module, the tooltip will contain the image size. You can also check these (and more) details in the Volumes module.

> [@the3dslicerdude](#):
>
> itk-snap I just clicked open segmentation and opened the nrrd and it imported and created the hundred or so masks within a few seconds

ITK-SNAP uses the legacy labelmap volume concept, whereas Slicer uses the more advanced PolySeg segmentations concept that allows overlapping segments, automatic conversions, etc. (see [this paper](http://perk.cs.queensu.ca/contents/polymorph-segmentation-representation-medical-image-computing)).

---

<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:** [July 19, 2019, 3:23pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/11 "2019-07-19T15:23:12Z")

</div>

Yes, segment editor is much more capable than ITK-snap but currently it uses an separate labelmap for each segment, which may require significantly more memory, especially when you have many segments.

We’ll make editing of hundreds of segments more efficient within a couple of months (allow sharing memory between segments, add filtering/searching in the segment list, etc.). Until then, you can edit up to 30-50 segments at a time and merge them into a single labelmap at the end (or upgrade your computer, mainly by add a lot of RAM).

---

<div class="post-metadata">

**Author:** ![tee](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tee](https://discourse.slicer.org/u/tee)\
**Post date:** [September 30, 2022, 2:13pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/12 "2022-09-30T14:13:52Z")

</div>

Sorry to revive this much later, but I hope someone can help: I am having a stack of png-images with 5 different colors in them. I’d like to segment this by color, mainly select the white background and remove it to 3D render the rest.

But when I try to load the image stack as a label map, I just get an error: “Error: Loading slices/slice\_000.png - load failed.”

Any hints on how to do this? Sorry, but absolute newbie with Slicer3D here.

---

<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 30, 2022, 2:33pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/13 "2022-09-30T14:33:47Z")

</div>

Do you have 5 discrete colors in your images (e.g., you painted those using some drawing tools) or you have 5 somewhat similar (not exactly the same) colors (e.g., from scanning images)?

---

<div class="post-metadata">

**Author:** ![tee](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tee](https://discourse.slicer.org/u/tee)\
**Post date:** [September 30, 2022, 4:28pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/14 "2022-09-30T16:28:14Z")

</div>

They are exact identical: results from a simulation and then assigned 5 specific RGB values. One is white (255,255,255) and should disappear, the rest should be visible segments.

---

<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 30, 2022, 7:41pm UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/15 "2022-09-30T19:41:49Z")

</div>

OK, it means that your data is actually a labelmap volume, not a color image. Therefore, it is better to save it as a scalar (single-channel) image. Use 0 for background and 1, 2, 3, 4, 5 for the segments. You can save it as png, but it would be much better to save the entire array as a single file, in nrrd format. You can find nrrd file writer for all programming languages, but if you are not sure which one to use then let us know.

You can load the nrrd file directly as segmentation, by choosing “Segmentation” in the “Description” column in the “Add data” window. You can make the file open as segmentation by default if you use `.seg.nrrd` as file extension.

---

<div class="post-metadata">

**Author:** ![tee](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tee](https://discourse.slicer.org/u/tee)\
**Post date:** [October 2, 2022, 11:28am UTC](https://discourse.slicer.org/t/new-segment-for-every-colour/7653/16 "2022-10-02T11:28:36Z")

</div>

Thanks for the explanation. Unfortunately the PNGs are the data I need to work with. Sounds like I need to transform them to that `nrrd` format first before I can visualize them.
