# Classify voxels via a predefined threshold

**URL:** <https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [January 17, 2023, 4:54pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308 "2023-01-17T16:54:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [January 17, 2023, 4:54pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/1 "2023-01-17T16:54:13Z")

</div>

Hi,

I am a user of 3Dslicer Mac version 5.2.1, with MarkUpsToModel, Sandbox and SegmentEditorExtraEffects extensions.  
I used the threshold tool on a paralumbar muscle after obtaining its volume and extraction but it did not succeed.

My goal is to obtain a muscle volume or a muscle area in binary color: black for the pure muscle and white for the fat in the muscle, via a predefined cutoff, like this exemple:

![Capture d’écran 2022-12-14 à 10.37.03](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/c/7c67f7f94c35148ef80c4c814b6cb8419ffced30.png)

This is what I get when using threshold, and it doesn’t work:

 ![Capture d’écran 2023-01-16 à 17.35.10](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/2/c2b48f3d48be2bb0712044fe9dc15f66851ccc9f.png)

No post seems to explain this subject precisely: on 3Dslicer, is it possible to carry out a binary classification of pixels or voxels via a predefined threshold in a gray scale?

Thanks

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [January 17, 2023, 8:18pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/2 "2023-01-17T20:18:14Z")

</div>

What have you tried so far? From your picture it seems that you are using the threshold visualization options in the Volume module.

Have you tried using the Segment Editor module? The Threshold editor effect may provide what you need. You can find documentation on the module here: [Segment editor — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmenteditor.html)

---

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [January 18, 2023, 3:23pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/4 "2023-01-18T15:23:19Z")

</div>

Thank you for your help.  
Indeed, I tried different threshold tools (SegmentEditor → Local threshold // Volume → threshold // Filtering → threshold scalar volume), but not this one.

Once the threshold is done and saved, how to get a percentage of black voxel and white voxel in a table? Currently, I get this table in Quantification → SegmentStatistics but it doesn’t separate the 2 colors I want to get.

 ![Capture d’écran 2023-01-18 à 16.19.35](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/e/bef31e472b713a062f2379e0231cc63ab0071933.png)

Thanks

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 18, 2023, 6:05pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/5 "2023-01-18T18:05:41Z")

</div>

> [@AmandineG](#):
>
> Once the threshold is done and saved, how to get a percentage of black voxel and white voxel in a table? Currently, I get this table in Quantification → SegmentStatistics but it doesn’t separate the 2 colors I want to get.

After you threshold, there is no black voxel or white voxel. Only the voxels that assigned to that segment, the count of which are given in the table under the Number of Voxels field.

If you use a different threshold and then create a new segment, you can simply divide these two numbers.

What are you trying to calculate?

---

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [January 19, 2023, 8:38am UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/6 "2023-01-19T08:38:05Z")

</div>

Thank you for your answer.

I’m trying to classify the pixels/voxels in a total muscle on MRI in a binary way according to an intensity threshold/cutoff, for example:

- Black = pure muscle, and
- White = muscle fat (like the first image in my first post).

I would like to do this work on a volume and on a surface.  
The final goal would be to get the percentage of black and white pixels/voxels in the volume and the surface.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 19, 2023, 4:21pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/7 "2023-01-19T16:21:43Z")

</div>

Within a fixed region, If you set one threshold to define muscle + fat and set it as a segment, then create a second segment and threshold specific to the muscle only, you can do what I said above, which is

`(number of voxels in segment1 - number of voxels in segment2) / number of voxels in segment1 *100`

which will give you the percentage of fat voxels in the defined area.

But you have to keep the area exactly the same in both segments.

---

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [February 1, 2023, 10:31am UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/8 "2023-02-01T10:31:45Z")

</div>

Thank you so much for your reply!

I tried to apply your method but there is an error:  
If I explode it in voxels, my volume of interest is 621650 voxels.  
With the same thresholding at 75 :

- If I choose to take the fat (white) in my volume of interest, it makes 188201 voxels.
- If I choose to take the pure muscle (black) in my volume of interest, it makes 431195 voxels.
- If I sum the two, I should in theory find the voxels of my total volume, that is 621650 voxels. Now, 188201+431195=619396.  
 → Do you know where the lost voxels are?

Moreover, in the table created with the Segment statistics tool, they describe volume (1) (columns B C D), volume (2) (columns E F G), volume (3) (columns N O) cf image. What do the (1) (2) (3) correspond to?

 ![Capture d’écran 2023-01-31 à 14.57.45](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/2/c2ad15fc4a9f2e22321c9e6930d7cddbe3632ebc.png)

 ![Capture d’écran 2023-01-31 à 14.58.09](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/6/d6bd8149a3fe44c98f88aec7ad1b876b915b730c.png)

Thanks

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 1, 2023, 6:30pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/10 "2023-02-01T18:30:49Z")

</div>

> [@AmandineG](#):
>
> I tried to apply your method but there is an error:  
> If I explode it in voxels, my volume of interest is 621650 voxels.  
> With the same thresholding at 75 :

Actually I found my mistake do it this way and you will get correct values

1. Download MRhead sample data
2. create three empty segments
3. In the first segment using the paint brush in 3D mode create a spherical region (I used 10%) in the center of the brain
4. Copy this region to segment\_2 and Segment\_3 using Logical Operators
5. Hide segment\_1
6. Switch to Segment\_2, go to threshold tool and enter these threshold values 0 - 34.99 and then set the Masking fields to: Editable area to Inside Segment\_2 and then modify other segments: Overwrite Visible (your segment\_3 should be visible, that important). Then hit apply.
7. Turn the visibility on for segment\_1, go to segment editor and calculate values.

You will see that sum of voxel counts of segment\_2 and segment\_3 are now identical to the segment\_1. This procedure split the original region into two none overlapping segmentations. You can adopt this procedure to your own dataset.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/4/c4f0af6d8d5697d5cacb8b7568fd5e4d266e4c16.jpeg)

---

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [February 7, 2023, 2:48pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/11 "2023-02-07T14:48:32Z")

</div>

> [@muratmaga](#):
>
> Logical Operators

Thank you for your reply!

I’m trying with MRhead sample data but it’s not very clear for me : what is “Logical Operators”?

Moreover, in your table, they describe volume (1) (columns B C D), volume (2) (columns E F G), volume (3) (columns N O). What do the (1) (2) (3) correspond to?

Thanks

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 7, 2023, 3:53pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/12 "2023-02-07T15:53:11Z")

</div>

@AmandineG you can find answers to your questions here:

[https://slicer.readthedocs.io/en/latest/user\_guide/modules/segmenteditor.html#logical-operators](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmenteditor.html#logical-operators)

[https://slicer.readthedocs.io/en/latest/user\_guide/modules/segmentstatistics.html](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentstatistics.html)

---

<div class="post-metadata">

**Author:** ![AmandineG](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@AmandineG](https://discourse.slicer.org/u/AmandineG)\
**Post date:** [February 9, 2023, 4:58pm UTC](https://discourse.slicer.org/t/classify-voxels-via-a-predefined-threshold/27308/13 "2023-02-09T16:58:36Z")

</div>

Thank you so much for your help and these links!

I was able to apply your threshold method on MRhead and then on my MRI. This technique is really easier, thank you.

Concerning the volumes and the “Segment Statistics” table, I understood that (1) (2) and (3) represent different volumes, but according to you, which volume represents better the reality (i.e. the real volume) between Labelmap statistics, scalar volume statistics or closed surface statistics?  
A topic has already been opened concerning this question but there is no answer ( [Differences between closed surface volume, labelmap volume and scalar volume](https://discourse.slicer.org/t/differences-between-closed-surface-volume-labelmap-volume-and-scalar-volume/23556) ).

Thanks
