# Threshold range lower value script vs GUI

**URL:** https://discourse.slicer.org/t/threshold-range-lower-value-script-vs-gui/38563
**Category:** Support
**Tags:** segmentation, python
**Created:** [September 26, 2024, 9:25pm UTC](https://discourse.slicer.org/t/threshold-range-lower-value-script-vs-gui/38563 "2024-09-26T21:25:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![G\_Tom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/g_tom/32/68257_2.png) [@G\_Tom](https://discourse.slicer.org/u/G_Tom)
#### Post date: [September 26, 2024, 9:25pm UTC](https://discourse.slicer.org/t/threshold-range-lower-value-script-vs-gui/38563/1 "2024-09-26T21:25:38Z")

</div>

hi, I am using a python script to threshold an image after first testing in the GUI.  
I am noticing that the threshold behaves differently ( different results) between the script and when doing threshold in the GUI.  
The pain reason I think is that the Lower bound of the threshold in the GUI seems to be updated automatically. How can I recreate this in a script ?

> ```
> segmentationNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
> segmentationNode.SetName('Segmentation_Image')
> segmentationNode.CreateDefaultDisplayNodes() # only needed for display    
> segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(inputVolumeNode)
> addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("Segment_BBs")
> 
> # Create segment editor to get access to effects
> segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
> segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
> segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
> segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
> 
> segmentEditorWidget.setSegmentationNode(segmentationNode)
> segmentEditorWidget.setSourceVolumeNode(inputVolumeNode)
> 
> # Thresholding
> segmentEditorWidget.setActiveEffectByName("Threshold")
> effect = segmentEditorWidget.activeEffect()
> effect.setParameter("AutoThresholdMethod", "Maximum entropy")
> effect.setParameter("AutoThresholdMode", "SET_LOWER_MAX")
> effect.self().onApply()
> 
> ```

Thanks

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/6/e6f4712ae683dd313197a8c712891effe86d1bec.png)  
Result in GUI:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/0/20c16485aac15726270747a0e7d8e37674ea672e.png)  
Result from scrip:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/0/20b668f7d8e34965becfdffd77b07468f2fb4cf3.jpeg)

GT
