# Window width/level range calculation

**URL:** <https://discourse.slicer.org/t/window-width-level-range-calculation/19010>\
**Category:** Support\
**Tags:** python\
**Created:** [August 1, 2021, 7:16am UTC](https://discourse.slicer.org/t/window-width-level-range-calculation/19010 "2021-08-01T07:16:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![siyuan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/siyuan/32/11091_2.png) [@siyuan](https://discourse.slicer.org/u/siyuan)\
**Post date:** [August 1, 2021, 7:16am UTC](https://discourse.slicer.org/t/window-width-level-range-calculation/19010/1 "2021-08-01T07:16:27Z")

</div>

Hi, recently I found the automatic adjustion of window width and level using a selected region in Slicer was quite useful. I want to implement it in my own way in python using SimpleITK. I’ve checked VTK website but found littile information there. Here is what I found in the forum (a simlilar topic [How to change window/level programmatically](https://discourse.slicer.org/t/how-to-change-window-level-programmatically/9043)) and locate the algorithm right here: [VTK/vtkImageHistogramStatistics.cxx at 6a9c565da01bcd6295d0bcbb66c0a9d0d2eaa69e · Kitware/VTK · GitHub](https://github.com/Kitware/VTK/blob/6a9c565da01bcd6295d0bcbb66c0a9d0d2eaa69e/Imaging/Statistics/vtkImageHistogramStatistics.cxx)

---

<div class="post-metadata">

**Author:** ![siyuan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/siyuan/32/11091_2.png) [@siyuan](https://discourse.slicer.org/u/siyuan)\
**Post date:** [August 1, 2021, 5:02pm UTC](https://discourse.slicer.org/t/window-width-level-range-calculation/19010/2 "2021-08-01T17:02:44Z")

</div>

I was wondering whether the range is calculated based on the histogram or simply min-max value of selected region.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [August 1, 2021, 7:33pm UTC](https://discourse.slicer.org/t/window-width-level-range-calculation/19010/3 "2021-08-01T19:33:46Z")

</div>

Window/Level based on selection area is discussed at [Feedback requested: How to improve mouse interaction in views? - #12 by lassoan](https://discourse.slicer.org/t/feedback-requested-how-to-improve-mouse-interaction-in-views/6420/12)

Auto Window/Level was changed from a histogram bimodal analysis to a fixed percentile based method. It was updated in Slicer as [ENH: Improved automatic scalar volume display window/level computation · Slicer/Slicer@bc0d938 · GitHub](https://github.com/Slicer/Slicer/commit/bc0d938c639cb7c3d87a816cf24b3be73542c09b)

---

<div class="post-metadata">

**Author:** ![siyuan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/siyuan/32/11091_2.png) [@siyuan](https://discourse.slicer.org/u/siyuan)\
**Post date:** [August 2, 2021, 5:26pm UTC](https://discourse.slicer.org/t/window-width-level-range-calculation/19010/5 "2021-08-02T17:26:25Z")

</div>

Thanks lot. It wll be of great help if you can explain the idea behind the auto-windowing method of selection area. 😃
