# How to change the label value of binary labelmap volume?

**URL:** <https://discourse.slicer.org/t/how-to-change-the-label-value-of-binary-labelmap-volume/12511>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [July 13, 2020, 6:11pm UTC](https://discourse.slicer.org/t/how-to-change-the-label-value-of-binary-labelmap-volume/12511 "2020-07-13T18:11:15Z")\
**Posts on this page:** 1\
**Showing post:** 9

<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 15, 2020, 3:55am UTC](https://discourse.slicer.org/t/how-to-change-the-label-value-of-binary-labelmap-volume/12511/9 "2020-07-15T03:55:06Z")

</div>

> [@N.Arjmandi](#):
>
> I want to segment the organs using deep learning.
> 
> In the next step, Python software will be used.

I’ve added a few code snippets that should be useful: [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_information_from_segmentation_nrrd_file_header)

`extract_segments` extracts segments by name and sets their label in the output voxel array to specified values. To achieve what you described, you would need to run these few lines:

```python
input_filename = "/path/to/input.seg.nrrd"
output_filename = "/path/to/outpput.seg.nrrd"
segment_list = [("bladder", 2), ("rectum", 3), ("prostate", 5)]

voxels, header = nrrd.read(input_filename)
read_segmentation_info(input_filename)
output_voxels, output_header = extract_segments(voxels, header, segmentation_info, segment_list)
nrrd.write(output_filename, output_voxels, output_header)

```

---

_[View the full topic](https://discourse.slicer.org/t/how-to-change-the-label-value-of-binary-labelmap-volume/12511)._
