Exporting CSV with parenchyma analysis module

This is the expected behavior if you export the segmentation to labelmap without specifying a mapping from segment names to label values.

You could change the label values quite easily manually, using numpy, but it is more elegant to specify a color mapping from segment names to label values using a color table node. You can create a color node that matches label values of CIP conventions for a few labels like this:

segmentToLabelValueMapping = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLColorTableNode", "CIP colors")
segmentToLabelValueMapping.SetTypeToUser()
segmentToLabelValueMapping.HideFromEditorsOff()
segmentToLabelValueMapping.SetNumberOfColors(69)
segmentToLabelValueMapping.SetColor( 0, "background", 0.0, 0.0, 0.0, 0.0)
segmentToLabelValueMapping.SetColor( 1, "whole lung", 0.42, 0.38, 0.75, 1.0)
segmentToLabelValueMapping.SetColor( 2, "right lung", 0.26, 0.64, 0.10, 1.0)
segmentToLabelValueMapping.SetColor( 3, "left lung",  0.80, 0.11, 0.36, 1.0)
segmentToLabelValueMapping.SetColor(58, "trachea",    0.49, 0.49, 0.79, 1.0)
segmentToLabelValueMapping.NamesInitialisedOn()

You can then specify this color table when you export the segmentation to labelmap to get the desired label values.

@rbumm if you want to make it easier to use LungCTAnalyzer segmentations with CIP then you could create a color node like this in the segmentation module and set it in the segmentation node. I think it would be used by default when you export the segmentation to labelmap.

1 Like