# Bring images to a uniform color window

**URL:** <https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940>\
**Category:** Support\
**Created:** [July 13, 2023, 8:17am UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940 "2023-07-13T08:17:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manju](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manju/32/7440_2.png) [@Manju](https://discourse.vtk.org/u/Manju)\
**Post date:** [July 13, 2023, 8:17am UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940/1 "2023-07-13T08:17:52Z")

</div>

Hi all… I am working with the enhancement of raw images (read as vtkImageData\*) which come in at varied exposure levels. The optimum color window and level vary drastically from image to image. Therefore, a lot of manual adjustment is required. I would like to bring the color window and level to a uniform value - while adjusting the image scalar values accordingly. Are there any methods/tools in VTK to do this without compromising the image clarity/enhancement? Would really appreciate any input or pointers.

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [July 14, 2023, 3:41am UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940/2 "2023-07-14T03:41:32Z")

</div>

Perhaps I don’t understand the question correctly but if the optimum window width/level values vary, can’t you just update those values when the image changes?

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [July 14, 2023, 2:28pm UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940/3 "2023-07-14T14:28:09Z")

</div>

Hello,

Can you, please, post two figures: a) illustrating what you have and b) what you need?

best,

PC

---

<div class="post-metadata">

**Author:** ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)\
**Post date:** [July 14, 2023, 6:44pm UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940/4 "2023-07-14T18:44:46Z")

</div>

The filter [vtkImageHistogramStatistics](https://vtk.org/doc/nightly/html/classvtkImageHistogramStatistics.html) can do some very basic image analysis to find a good Window/Level for an image. It has a test program, [ImageAutoRange.cxx](https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.0/Imaging/Core/Testing/Cxx/ImageAutoRange.cxx), that shows how it is used.

```cpp
  // compute the image histogram
  vtkNew<vtkImageHistogramStatistics> statistics;
  statistics->SetInputData(image);
  statistics->Update();

  // find a good range based on histogram percentiles
  double autorange[2];
  statistics->GetAutoRange(autorange);

  // set the window/level for the image that is being displayed
  property->SetColorWindow(autorange[1] - autorange[0]);
  property->SetColorLevel(0.5 * (autorange[0] + autorange[1]));

```

---

<div class="post-metadata">

**Author:** ![Manju](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manju/32/7440_2.png) [@Manju](https://discourse.vtk.org/u/Manju)\
**Post date:** [August 22, 2023, 11:23am UTC](https://discourse.vtk.org/t/bring-images-to-a-uniform-color-window/11940/5 "2023-08-22T11:23:29Z")

</div>

Apologies for the very late reply. Thank you so much for suggesting this!
