# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ezio\_Lanza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ezio_lanza/32/6285_2.png) [@Ezio\_Lanza](https://discourse.slicer.org/u/Ezio_Lanza)\
**Post date:** [March 16, 2020, 11:07am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/1 "2020-03-16T11:07:45Z")

</div>

Hello everyone,  
I’m having troubles exporting results from the parenchyma analysis module in CSV. It only exports the first row without the resulting values. Also, I cannot copy and paste to excel which instead is possible when using the scalar volume module

Any clue? I’m using slicer 4 on MAC

Thanks

---

<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:** [March 18, 2020, 4:09am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/2 "2020-03-18T04:09:20Z")

</div>

I’m not sure if CIP developers monitor the Slicer forum. Could you try to contact them directly and let us know if they respond?

@raul

---

<div class="post-metadata">

**Author:** ![Ezio\_Lanza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ezio_lanza/32/6285_2.png) [@Ezio\_Lanza](https://discourse.slicer.org/u/Ezio_Lanza)\
**Post date:** [March 18, 2020, 1:43pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/3 "2020-03-18T13:43:57Z")

</div>

Thanks for answering  
I couldn’t find any email address to contact them

---

<div class="post-metadata">

**Author:** ![raul](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raul/32/1140_2.png) [@raul](https://discourse.slicer.org/u/raul)\
**Post date:** [March 18, 2020, 2:21pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/4 "2020-03-18T14:21:10Z")

</div>

Hi Ezio,

Thank you for your email and sorry for the trouble.

Can you provide more info about the Slicer version that you are using to try to reproduce the results?

Are you able to see the results in the module table before exporting the values? A screenshot of a test case might be helpful

Thanks

Raul

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 8, 2021, 12:50pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/5 "2021-08-08T12:50:58Z")

</div>

Hi there,

Sorry, I am new to this and I am also having trouble.

1. I am not able to export the data in parenchyma analysis in CSV format.
2. I can only export one parameter each time. Is there a way to export all the results at one go?
3. I tried using my own segmentation label map volume (using segment editor). My histogram does not look correct. My left lung histogram is flat. I am not sure what I am doing wrong.

 ![segmentation histogram](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/5/a5785fc77967126424c24d4d4b939296fe2db534.jpeg)

---

<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 8, 2021, 2:00pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/6 "2021-08-08T14:00:08Z")

</div>

How did you segment the lungs? Using Segment Editor module? Have you clicked “Apply” in “Grow from seeds” effect after the preview looked good?

You could also consider using the LungCTAnalyzer extension. If you miss some features (e.g., want to compute histogram) then probably @rbumm could easily add it.

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 8, 2021, 2:35pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/7 "2021-08-08T14:35:22Z")

</div>

Thanks for your reply!

I used this youtube video as a guide: [COVID-19 lung CT segmentation using 3D Slicer - YouTube](https://www.youtube.com/watch?v=v1-L_niLZxQ)

1. Set threshold as mask (HU -1024 to -200)
2. using paint to draw general outlines for right lung, left lung and trachea
3. Click on grow from seeds and initialize
4. Add additional areas of paint for regions that need correction
5. Click on apply under grow from seeds to finalize
6. Export as new label map volume
7. Go to parenchyma analysis and select input CT volume and the newly created label map volume
8. Click on apply

I tried the lung CT segmenter extension as well (using landmarks for right lung, left lung and trachea). I still get the same flat histogram for left lung

 ![threshold](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/b/2b01af79143bc1fce43cc044f233c93ab07ed6ad.jpeg)  
 ![applied after grow from seed](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/f/cfdc0ee7eca906d7c50fc664b547ae176244e3f3.jpeg)  
 ![lung ct segmenter](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/2/8247e39c1ecfc26a68c807dddfb24015f0ded132.jpeg)

I am trying to use other parameters (such as perc 85%) to analyze lung fibrosis.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 8, 2021, 3:14pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/8 "2021-08-08T15:14:52Z")

</div>

You do not have to do lung masks in “Parenchyma Analysis”. Just set the input volume to the lung CT dataset and leave the “Label map volume” set to “None”, then press “Apply”.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/9/a979d05bc9f979a1029b4563da82f30408a4645b.jpeg)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/8/98ee3b4289ecf540b4829a2c74886416219ccb71.jpeg)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 8, 2021, 3:22pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/9 "2021-08-08T15:22:32Z")

</div>

@lassoan Having a histogram in the LungCTAnalyzer is probably good idea !

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 8, 2021, 4:05pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/10 "2021-08-08T16:05:46Z")

</div>

I see, thanks! I will try to use the native label map volume from “Parenchyma Analysis” as much as possible.

My only concern is if there are some studies where the automated segmentation by the “Parenchyma Analysis” is not optimal and I have to manually edit some areas. In that case, I am worried that this issue will again recur.

I would also like to ask if there is any way to export the data in “Parenchyma Analysis” as a CSV file?

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 8, 2021, 5:23pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/11 "2021-08-08T17:23:25Z")

</div>

I am not the developer of this extension but - yes, after “Parenchyma analysis” and if you go into the “Data” extension, you see, that the results of the analysis are stored in table nodes.

When saving your scene select the CSV format:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/1/f1e4d496a5cb9a6ebf19a83ab936b037ac8a0bda.png)

---

<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 8, 2021, 9:33pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/12 "2021-08-08T21:33:44Z")

</div>

The flat histogram looks good, it belongs the trachea (or “other”) segment, which is very small and dark compared to the two lung segments.

The Parenchyma Analysis module probably uses hardcoded label values, which are not the same as the values that are used when you export the segmentation that was created in Lung CT segmentation module. The module should be modernized so that it can use segmentation as input (so that we don’t need to rely on hardcoded label values anymore). The module should also modernized so that for plotting it does not use Charts (that will be removed soon from Slicer) but Plots.

You can [compute the histogram of a segmented region by a few lines of Python code](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-histogram-of-a-segmented-region), so it would be easy to add it to Lung CT analyzer module. But it is probably better to not create modules with overlapping features but fix/modernize the existing module instead.

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 9, 2021, 7:45am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/13 "2021-08-09T07:45:46Z")

</div>

Thanks alot!

That is very helpful

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 9, 2021, 7:47am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/14 "2021-08-09T07:47:19Z")

</div>

I see!

I am not very experienced with Python coding but I will play around with it. Does that mean I can possibly add in my own parameters for analysis (such as other percentile densities instead of the ones provided)?

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 9, 2021, 12:15pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/15 "2021-08-09T12:15:53Z")

</div>

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 original histogram with “right lung” on 1st in order by default:

 ![original parenchymal analysis](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/f/af9656f5b66d4ab3d64b9daa369b1558fd183091.jpeg)

After I switch the order, putting “left lung” 1st in order as follows:

 ![left lung segment](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/6/869fe9e3e18c0d8269c734632a5ea73b3dcc0d39.jpeg)

I get the histogram for the “left lung” but it is labelled as the “right lung” in “parenchymal analysis”

 ![new parenchymal analysis](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/e/fefd469efacd2d073e8e791075b1cecb2eb9799c.jpeg)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 9, 2021, 1:33pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/16 "2021-08-09T13:33:13Z")

</div>

Yes you could do that, the python code is exposed in that extension.  
You would need to switch Slicer to “Enable developer mode” under “Application Settings” \> “Developer”, then you would be able to “Edit” and “Reload” the extension code (with great care)

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/1/81301677183f7cb8d613ebe1440bda417af36d9f.png)

---

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

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 9, 2021, 7:51pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/18 "2021-08-09T19:51:57Z")

</div>

Done and working (created in 4.13, CIP tested vs 4.11).

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/6/a6a4c1c5dd70ca9b3977ceba83160441f972f320.png)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [August 10, 2021, 8:09am UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/19 "2021-08-10T08:09:49Z")

</div>

That success message was too early.  
I will create an issue in LungCTAnalyzer to prevent pushing this up all the time in discourse.

> <https://github.com/rbumm/SlicerLungCTAnalyzer/issues/27>
>
> I implemented the code in LungCTSegmenter  mentioned here
> 
> \[https://discourse.…slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/17?u=rbumm\](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/17?u=rbumm)
> 
> but this
> 
> !\[image\](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/2X/a/a4bcef1500c54fa3c4fa175c37c7d85e79b4471e.png)
> 
> was produced leaving the labelmap input to "None". 
> 
> If I do a LungCTSegmenter run with the latest code and do this
> 
> !\[\](https://user-images.githubusercontent.com/18140094/128834443-38f0520a-d77f-415c-8d20-f59b1d45439d.png)
> 
> I get this (Lung segmentation-label. 
> 
> !\[\](https://user-images.githubusercontent.com/18140094/128834627-4e273f23-31a8-4eb7-9784-5473368a9bc6.png)
> 
> Feeding this to CIP and "Parenchyma Analysis" 
> 
> !\[\](https://user-images.githubusercontent.com/18140094/128835036-6f4a6995-cb9b-4784-bb97-8e92a58ece95.png)
> 
> still results in
> 
> !\[\](https://user-images.githubusercontent.com/18140094/128834904-0a9c5304-2cc2-47a4-9ee9-ae2a88453b2b.png)

---

<div class="post-metadata">

**Author:** ![chuawm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chuawm/32/11915_2.png) [@chuawm](https://discourse.slicer.org/u/chuawm)\
**Post date:** [August 21, 2021, 5:48pm UTC](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697/20 "2021-08-21T17:48:01Z")

</div>

> [@lassoan](#):
>
> `segmentToLabelValueMapping.NamesInitialisedOn()`

Sorry Lassoan,

I tried changing the label values to match those of CIP conventions as per your suggestion. I used the exact labels which you kindly provided.

 ![labelvaluemapping](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/1/c1e70e9927ba6a7a5fd35864325e45303efe8cba.jpeg)  
However, my histogram still looks flat for the left lung.  
 ![new parenchymal analysis](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e30ad1ba43454b65dce3ee5bffc259255e66debb.jpeg)

Do you know where did I go wrong?

[Next page](https://discourse.slicer.org/t/exporting-csv-with-parenchyma-analysis-module/10697.md?page=2)
