In my workflow I am importing an 8 bit greyscale volume/mask where each pixel corresponds to a subregion. Some of the pixel values are rather high (e.g. ,227), and there are gaps between the classes (some intermediate pixel values do not have a class); e.g., 60, 61, then jump to 200. In my workflow I convert these to segments, smoothen, and then I want to export a new greyscale volume that preserves the orginal pixel values I imported (e.g., 227 still 227). I noticed that when the segments get converted back to a volume (both when I try to export the segments, or convert them to a labelmap within slicer), the 227 value become ~70(ish). Other high pixels change there values. Is each original value forced to count sequentially up. So say if my classes were 1,2,3,10; does slicer always make this 1,2,3,4 when it converts from the segments back to volume?
I noticed the exported volume is always 16 bit. Does this have anything to do with it?
Might the segments overlap after smoothing? If so, the output segments may not be able to be fully represented in a single labelmap.
If they don’t overlap, then you can just get each segment as a binary labelmap and then use that as a binary mask to apply the label number you want to each segment. That should all be pretty straightforward to accomplish with python and numpy. (If the segments do overlap, you would need to decide how to handle conflicts where the same voxel is claimed by more than one segment
Thanks for the pointers Mike. So it sounds like there is no way to preserve the pixel identities (with gaps/jumps between pixel values) when I convert from segments back to labelmaps? Can you confirm that it just rebuilds the pixels from the list, starting at the top as 1, and counting up 1 pixel per group. I think this is how it’s behaving but it would help to be certain, so I can relabel in python as you suggest. I am managing 75 labels, so my process is prone to error.
Maybe a whole different problem: but at some point I want to convert back to 8 bit, and suspect there will be low-depth rounding errors that merge the pixel classes. Can I create an 8 bit labelmap file?
Still, does anyone know of a way within slicer to convert from segments to labelmaps and preserve the gaps in assigned pixel values?
If you want to have non-continuous labelmap values (e.g., 1, 2, 4, 10, 50), you need to define a color table ( Colors — 3D Slicer documentation ) to tell Slicer what index each segment going to get, and then specify that while you are exporting the segmentation to labelmap. Otherwise Slicer while export them in the order they are in the segmentation table, starting from 1.