# How is mean attenuation calculated?

**URL:** <https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594>\
**Category:** Support\
**Created:** [September 9, 2021, 12:47pm UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594 "2021-09-09T12:47:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Brahier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mark_brahier/32/5934_2.png) [@Mark\_Brahier](https://discourse.slicer.org/u/Mark_Brahier)\
**Post date:** [September 9, 2021, 12:47pm UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594/1 "2021-09-09T12:47:27Z")

</div>

How does 3D slicer calculate the output ‘mean attenuation’? For example, I select the range of -190 to -30 HU to capture adipose tissue, and I am interested in both the volume and mean attenuation. I always assumed that ‘mean’ references to the average attenuation value for each individual pixel identified within that -190 to -30 range, but I would appreciate it if someone could clarify/explain. 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:** [September 10, 2021, 3:32am UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594/2 "2021-09-10T03:32:58Z")

</div>

The “Mean” column of Segment statistics module output table contains the mean value of all voxel values in the segment’s region.

---

<div class="post-metadata">

**Author:** ![Mark\_Brahier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mark_brahier/32/5934_2.png) [@Mark\_Brahier](https://discourse.slicer.org/u/Mark_Brahier)\
**Post date:** [September 13, 2021, 12:38pm UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594/3 "2021-09-13T12:38:47Z")

</div>

Thank you. Would you be able to share the Python code for attenuation, both the code for volume within an attenuation range and for mean attenuation?

---

<div class="post-metadata">

**Author:** ![Mark\_Brahier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mark_brahier/32/5934_2.png) [@Mark\_Brahier](https://discourse.slicer.org/u/Mark_Brahier)\
**Post date:** [September 16, 2021, 10:37pm UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594/4 "2021-09-16T22:37:37Z")

</div>

Just following this again again… would you be able to link me to the Python code for this? Thank you!!

---

<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:** [September 17, 2021, 1:52pm UTC](https://discourse.slicer.org/t/how-is-mean-attenuation-calculated/19594/5 "2021-09-17T13:52:37Z")

</div>

Segment statistics module is implemented in Python (see [source code](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SegmentStatistics/SegmentStatistics.py)). You can either use VTK or ITK filters or numpy (get the voxels as a numpy array, use masking to get the voxels in the segment’s region, and get the mean by calling the `mean` method of the masked array).
