How to change the label value of binary labelmap volume?

I’ve added a few code snippets that should be useful: Documentation/Nightly/ScriptRepository - Slicer Wiki

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:

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)