# Get Voxel count off of LabelMapNode?

**URL:** <https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501>\
**Category:** Support\
**Created:** [June 14, 2017, 3:29pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501 "2017-06-14T15:29:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jks1995](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jks1995](https://discourse.slicer.org/u/jks1995)\
**Post date:** [June 14, 2017, 3:29pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/1 "2017-06-14T15:29:54Z")

</div>

How would I get the number of voxels off of a label map node?

---

<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:** [June 14, 2017, 3:43pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/2 "2017-06-14T15:43:21Z")

</div>

Use Labelmap statistics module to get the number of non-zero voxels.

---

<div class="post-metadata">

**Author:** ![jks1995](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jks1995](https://discourse.slicer.org/u/jks1995)\
**Post date:** [June 14, 2017, 5:44pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/3 "2017-06-14T17:44:41Z")

</div>

How would I go about that?

---

<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:** [June 15, 2017, 2:17am UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/4 "2017-06-15T02:17:29Z")

</div>

- Open Label statistics module
- Select Grayscale volume
- Select Label map volume
- Click Apply

`Count` column contains the number of voxels.

---

<div class="post-metadata">

**Author:** ![jks1995](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jks1995](https://discourse.slicer.org/u/jks1995)\
**Post date:** [June 15, 2017, 2:33pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/5 "2017-06-15T14:33:55Z")

</div>

How would I access this through python?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 15, 2017, 3:14pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/6 "2017-06-15T15:14:43Z")

</div>

The module is written in Python, so any specific functionality could be easily extracted/duplicated in your own script. Here is the relevant section:

> <https://github.com/Slicer/Slicer/blob/eefeac9286f48552e8418a11f412b2823a09b407/Modules/Scripted/LabelStatistics/LabelStatistics.py#L310-L345>

---

<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:** [June 15, 2017, 4:36pm UTC](https://discourse.slicer.org/t/get-voxel-count-off-of-labelmapnode/501/7 "2017-06-15T16:36:38Z")

</div>

If you want to build anything on this, then I would strongly recommend to switch to Segmentations/Segment Editor/Segment statistics modules now. These modules are much more capable than the old Editor/Label statistics - those old modules will be kept around for a while but they will not be developed any further.

See complete example of using Segment statistics in Python below. You can run the test by enabling developer mode in Slicer application settings, opening Segment statistics module, and clicking on `Reload and test` button.

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SegmentStatistics/SegmentStatistics.py#L435-L483>
