# How does Slicer finds the optimal viewing window (min/max values) when importing nifti file?

**URL:** <https://discourse.slicer.org/t/how-does-slicer-finds-the-optimal-viewing-window-min-max-values-when-importing-nifti-file/2763>\
**Category:** Support\
**Tags:** nifti\
**Created:** [May 6, 2018, 1:41pm UTC](https://discourse.slicer.org/t/how-does-slicer-finds-the-optimal-viewing-window-min-max-values-when-importing-nifti-file/2763 "2018-05-06T13:41:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaglisR](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/naglisr/32/16280_2.png) [@NaglisR](https://discourse.slicer.org/u/NaglisR)\
**Post date:** [May 6, 2018, 1:41pm UTC](https://discourse.slicer.org/t/how-does-slicer-finds-the-optimal-viewing-window-min-max-values-when-importing-nifti-file/2763/1 "2018-05-06T13:41:30Z")

</div>

Hi,

I want to find out how does Slicer determines the optimal viewing window (min/max values) when importing nifti file. I know that when importing dicoms the windowing info is in the metadata, however as far as I know nifti and nrrd files does not contain this info in the metadata. How is Slicer able to display the correct viewing window (for the brain tissue) after importing a nifti file?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 6, 2018, 3:45pm UTC](https://discourse.slicer.org/t/how-does-slicer-finds-the-optimal-viewing-window-min-max-values-when-importing-nifti-file/2763/2 "2018-05-06T15:45:39Z")

</div>

It’s done in the code linked below - basically it is heuristic that looks at the histogram and expects a big hump of dark background, and then a hump of brighter foreground (a reasonable approximation of most CT and MR images). Then it ignores the background and picks a range around the foreground.

> <https://github.com/Slicer/Slicer/blob/cdcfeb14564316be607c2c062ca4e418753d1c40/Libs/MRML/Core/vtkMRMLScalarVolumeDisplayNode.cxx#L708-L862>
