Can I modify the nrrd file saved with the 3D Slicer?

Now I’m working on annotating with the 3D Slicer.

During Annotation, I saved the Volume and looked inside to see that it was saved as index, not color.

My goal is to change this index.

For example, if you annotate using 10 colors, numbers from 1 to 10 will be generated, and I want to change the number 5 to 7.

Is this possible in the 3D Slicer?

If you save segmentation as 4D .seg.nrrd file (to allow overlapping segments) then color indices are not used, but each segment is stored with 0/1 values along the 4th dimension. You can look up the index of each segment in the custom metadata fields in the file header.

If you export the segmentation to a merged labelmap before writing to a 3D nrrd file, you can change voxel values using numpy before writing to file:

volumeNode = getNode('Segmentation-label')

volumeArray=slicer.util.arrayFromVolume(volumeNode)
volumeArray[volumeArray==5] = 7 # change all voxel values of 5 to 7
slicer.util.arrayFromVolumeModified(volumeNode)
1 Like