# Exporting CSV with parenchyma analysis module

**URL:** <https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697>\
**Category:** Support\
**Tags:** cip\
**Created:** [March 16, 2020, 11:07am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697 "2020-03-16T11:07:45Z")\
**Posts on this page:** 1\
**Showing post:** 17

<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:** [August 9, 2021, 3:12pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/17 "2021-08-09T15:12:03Z")

</div>

> [@chuawm](#):
>
> I realized that if I were to switch the order around in “segment editor”, where “left lung” comes before “right lung”, I will get the histogram for the “left lung” but it will be labelled as “right lung” in “parenchymal analysis”. Essentially, “parenchymal analysis” will create the histogram for the first segmentation accurately but not the others.

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](https://github.com/acil-bwh/ChestImagingPlatform/blob/8a9d9cf831c9f670518730c4e74365f34008f025/Common/cipChestConventions.cxx#L646-L714) for a few labels like this:

```python
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.

---

_[View the full topic](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697)._
