# Threshold function not working

**URL:** <https://discourse.slicer.org/t/threshold-function-not-working/29701>\
**Category:** Support\
**Created:** [May 29, 2023, 12:59am UTC](https://discourse.slicer.org/t/threshold-function-not-working/29701 "2023-05-29T00:59:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![umair04](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@umair04](https://discourse.slicer.org/u/umair04)\
**Post date:** [May 29, 2023, 12:59am UTC](https://discourse.slicer.org/t/threshold-function-not-working/29701/1 "2023-05-29T00:59:42Z")

</div>

I am trying to threshold different DICOM files to create segmentations, but some of the DICOM files are not working properly.

File working properly:

 ![Screenshot 2023-05-28 at 4.37.50 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/f/4fc46a5b7e7e8472387b955ff07fcde4b1136bcb.png)

File not working properly:

 ![Screenshot 2023-05-28 at 4.39.15 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/1/71254de9adb0ec3ea6c73755d83e88d6eab7ddfd.png)

I have numerous files that fall into either of the categories above: the image is fully highlighted during the thresholding process and creating a segmentation successfully, or it is only highlighting the edges and not creating a segmentation. How can I fix the second category to create segmentations?

---

<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:** [May 29, 2023, 1:04am UTC](https://discourse.slicer.org/t/threshold-function-not-working/29701/2 "2023-05-29T01:04:22Z")

</div>

Might be related to the extremely high (128K) max intensity value in your second datasets. Most DICOM datasets are 16 bit and goes up to 65K. You may want to rescale your intensity ranges for this dataset (using simple filters) and try anew.

---

<div class="post-metadata">

**Author:** ![umair04](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@umair04](https://discourse.slicer.org/u/umair04)\
**Post date:** [May 29, 2023, 1:27am UTC](https://discourse.slicer.org/t/threshold-function-not-working/29701/3 "2023-05-29T01:27:23Z")

</div>

That worked, 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:** [May 29, 2023, 2:09am UTC](https://discourse.slicer.org/t/threshold-function-not-working/29701/4 "2023-05-29T02:09:32Z")

</div>

FYI, this issue is fixed in recent Slicer Preview Releases:

> <https://github.com/commontk/CTK/commit/ef3d86b3b9053f4fa53e8e4a6ab9ab42db14f88b>
>
> The minimum and maximum values were not always reachable in ctkDoubleSlider and …ctkDoubleRangeSlider widgets when moved the slider to the minimum or maximum position.
> 
> For example:
> 
> \`\`\`
> lo = -1024
> hi = 2000
> step = (hi - lo) / 1000.
> 
> thresholdSlider = ctk.ctkRangeWidget()
> thresholdSlider.spinBoxAlignment = qt.Qt.AlignTop
> thresholdSlider.setRange(lo, hi)
> thresholdSlider.singleStep = step
> thresholdSlider.show()
> \# Impossible to reach 2000.0
> 
> slider = ctk.ctkDoubleSlider()
> slider.minimum = lo
> slider.maximum = hi
> slider.singleStep = step
> slider.show()
> slider.connect("valueChanged(double)", lambda v: print(v))
> \# Impossible to reach 2000.0
> \`\`\`
> 
> The problem was that the integer slider range was determined by rounding, which could result in the integer slider range not covering the entire value range.
> Fixed the problem by extending the integer slider range when it did not fully cover the value range.
> 
> Co-authored-by: Jean-Christophe Fillion-Robin \<jchris.fillionr@kitware.com\>
