# How to access Labelmap indexes and change them?

**URL:** <https://discourse.slicer.org/t/how-to-access-labelmap-indexes-and-change-them/34797>\
**Category:** Support\
**Created:** [March 9, 2024, 12:29pm UTC](https://discourse.slicer.org/t/how-to-access-labelmap-indexes-and-change-them/34797 "2024-03-09T12:29:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [March 9, 2024, 12:29pm UTC](https://discourse.slicer.org/t/how-to-access-labelmap-indexes-and-change-them/34797/1 "2024-03-09T12:29:39Z")

</div>

Hi everyone!

I´m trying to manage imports from mask volumes and have some trouble with index of segments inside them.

For example:  
I have a mask.nii.gz with 3 segments inside (1:bone, 2:fat , 3:muscle)  
I also have a ColorTable with values:  
1 muscle 255 0 0 255  
2 bone 0 255 0 255  
3 fat 0 0 255 255

I want to import mask file, reorder segments to match each one with ColorTable and then import LBM into SegmentationNode

It could be something like:

```auto
maskFilePath = ("//mask.nii.gz")
maskLBMNode = slicer.util.loadLabelVolume(maskFilePath)
label = slicer.util.arrayFromVolume(maskLBMNode)
# code to change indexes
slicer.util.arrayFromVolumeModified(maskLBMNode)
maskLBMNode.GetDisplayNode().SetAndObserveColorNodeID(colorTable.GetID())
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(maskLBMNode,outputSegmentationNode)
slicer.mrmlScene.RemoveNode(importLBMNode)

```

Thanks in advance!!!
