# Threshold min and max values

**URL:** <https://discourse.slicer.org/t/threshold-min-and-max-values/28643>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [March 29, 2023, 4:50am UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643 "2023-03-29T04:50:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)\
**Post date:** [March 29, 2023, 4:50am UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643/1 "2023-03-29T04:50:08Z")

</div>

I’m trying to create an automatic segment generator by using the threshold method for any given DICOM images.  
However, as it may seems, the values from the extremes of the range varies with distinct Volume Nodes provided in the Segmentation Editor.

Is there a way to calculate those values or to generalize them (making them constant to a given input)?

---

<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:** [March 29, 2023, 5:10am UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643/2 "2023-03-29T05:10:18Z")

</div>

You can use the automated threshold algorithms (shanbhag, isodata, otsu, etc…) for reproducibility.

---

<div class="post-metadata">

**Author:** ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)\
**Post date:** [March 29, 2023, 5:51pm UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643/3 "2023-03-29T17:51:01Z")

</div>

Yes, I’m attempting to do this.

However I’m not sure how to set the max and minimum values of the thresholdrange giving a certain DICOM image (and Volume Node consequently). I’m having a bad time to find this information in Slicer’s Github repo. Do you know where can I find it?

---

<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:** [March 29, 2023, 6:45pm UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643/4 "2023-03-29T18:45:49Z")

</div>

Automated threshold methods do not require min, max value of the volume. The calculate it based on the volume’s intensity distribution and the model they assume that to be (bimodal, trimodal etc).

You can obtain the min/max of the volume by reading the intensity values as a numpy array. Using MRhead as an example data.

```auto
>>> volumeNode = getNode("MRHead")
>>> voxels = slicer.util.arrayFromVolume(volumeNode)
>>> voxels.max()
279
>>> voxels.min()
0

```

---

<div class="post-metadata">

**Author:** ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)\
**Post date:** [March 29, 2023, 7:31pm UTC](https://discourse.slicer.org/t/threshold-min-and-max-values/28643/5 "2023-03-29T19:31:03Z")

</div>

Thank you very much!
