Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::LevelWindow Class Reference

The LevelWindow class Class to store level/window values. More...

#include <mitkLevelWindow.h>

Public Member Functions

 LevelWindow (ScalarType level=127.5, ScalarType window=255.0)
 Construct a LevelWindow with given level (center) and window (range) values. More...
 
 LevelWindow (const mitk::LevelWindow &levWin)
 Copy constructor. More...
 
virtual ~LevelWindow ()
 Virtual destructor. More...
 
ScalarType GetLevel () const
 Get the level value, i.e. the center of the current grey value interval. More...
 
ScalarType GetWindow () const
 Get the current window size, i.e. the width of the current grey value interval. More...
 
ScalarType GetDefaultLevel () const
 Get the default level value for the image. More...
 
ScalarType GetDefaultWindow () const
 Get the default window size for the image. More...
 
void ResetDefaultLevelWindow ()
 Reset the level and window to their default values. More...
 
ScalarType GetLowerWindowBound () const
 Get the lower bound of the current window. More...
 
ScalarType GetUpperWindowBound () const
 Get the upper bound of the current window. More...
 
void SetLevelWindow (ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
 Set the level and window values. More...
 
void SetWindowBounds (ScalarType lowerBound, ScalarType upperBound, bool expandRangesIfNecessary=true)
 Set the lower and upper window bounds directly. More...
 
void SetToMaxWindowSize ()
 Set the window to cover the entire valid range. More...
 
void SetRangeMinMax (ScalarType min, ScalarType max)
 Set the minimum and maximum of the valid value range. More...
 
ScalarType GetRangeMin () const
 Get the minimum of the valid value range. More...
 
ScalarType GetRangeMax () const
 Get the maximum of the valid value range. More...
 
ScalarType GetDefaultLowerBound () const
 Get the default lower bound (default range minimum). More...
 
ScalarType GetDefaultUpperBound () const
 Get the default upper bound (default range maximum). More...
 
void ResetDefaultRangeMinMax ()
 Reset the range min/max to the default boundaries. More...
 
ScalarType GetRange () const
 Get the total size of the grey value range (max - min). More...
 
void SetDefaultLevelWindow (ScalarType level, ScalarType window)
 Set the default level and window values. More...
 
void SetDefaultBoundaries (ScalarType low, ScalarType up)
 Set the default lower and upper boundaries. More...
 
void SetAuto (const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
 Automatically set level/window to optimize image contrast. More...
 
void SetToImageRange (const Image *image)
 Set level/window to the full min/max grey value range of the given image. More...
 
void SetFixed (bool fixed)
 Lock or unlock the level window settings. More...
 
bool GetFixed () const
 Return whether the level window settings are fixed. More...
 
bool IsFixed () const
 Return whether the level window settings are fixed. More...
 
virtual bool operator== (const LevelWindow &levWin) const
 Compare two LevelWindow objects for equality. More...
 
virtual bool operator!= (const LevelWindow &levWin) const
 Compare two LevelWindow objects for inequality. More...
 
virtual LevelWindow & operator= (const LevelWindow &levWin)
 Assignment operator. More...
 
bool IsFloatingValues () const
 Check whether the image uses floating-point values. More...
 
void SetFloatingValues (bool value)
 Set whether the image uses floating-point values. More...
 

Protected Member Functions

void EnsureConsistency ()
 

Protected Attributes

ScalarType m_LowerWindowBound
 
ScalarType m_UpperWindowBound
 
ScalarType m_RangeMin
 
ScalarType m_RangeMax
 
ScalarType m_DefaultLowerBound
 
ScalarType m_DefaultUpperBound
 
bool m_IsFloatingImage
 
bool m_Fixed
 

Detailed Description

The LevelWindow class Class to store level/window values.

Current min and max value are stored in m_LowerWindowBound and m_UpperWindowBound. m_DefaultLevel amd m_DefaultWindow store the initial Level/Window values for the image. m_DefaultRangeMin and m_DefaultRangeMax store the initial minrange and maxrange for the image.

The finite maximum and minimum of valid value range is stored in m_RangeMin and m_RangeMax. If deduced from an image by default the minimum or maximum of it statistics is used. If one of these values are infinite the 2nd extrimum (which is guaranteed to be finite), will be used.

See documentation of SetAuto for information on how the level window is initialized from an image.

Note
If you want to apply the mitk::LevelWindow to an mitk::Image, make sure to use the mitk::LevelWindowProperty and set the mitk::RenderingModeProperty to a mode which supports level window (e.g. LOOKUPTABLE_LEVELWINDOW_COLOR). Make sure to check the documentation of the mitk::RenderingModeProperty. For a code example how to use the mitk::LevelWindowProperty check the mitkImageVtkMapper2DLevelWindowTest.cpp in Core/Code/Testing.

Definition at line 43 of file mitkLevelWindow.h.

Constructor & Destructor Documentation

◆ LevelWindow() [1/2]

mitk::LevelWindow::LevelWindow ( ScalarType  level = 127.5,
ScalarType  window = 255.0 
)

Construct a LevelWindow with given level (center) and window (range) values.

Parameters
[in]levelThe center of the grey value interval (default: 127.5).
[in]windowThe width of the grey value interval (default: 255.0).

◆ LevelWindow() [2/2]

mitk::LevelWindow::LevelWindow ( const mitk::LevelWindow &  levWin)

Copy constructor.

Parameters
[in]levWinThe LevelWindow to copy.

◆ ~LevelWindow()

virtual mitk::LevelWindow::~LevelWindow ( )
virtual

Virtual destructor.

Member Function Documentation

◆ EnsureConsistency()

void mitk::LevelWindow::EnsureConsistency ( )
inlineprotected

confidence tests

if m_LowerWindowBound > m_UpperWindowBound, then the values for m_LowerWindowBound and m_UpperWindowBound will be exchanged

if m_LowerWindowBound < m_RangeMin, m_LowerWindowBound will be set to m_RangeMin. m_UpperWindowBound will be decreased the same as m_LowerWindowBound will be increased, but minimum value for m_UpperWindowBound is also m_RangeMin.

if m_UpperWindowBound > m_RangeMax, m_UpperWindowBound will be set to m_RangeMax. m_LowerWindowBound will be increased the same as m_UpperWindowBound will be decreased, but maximum value for m_LowerWindowBound is also m_RangeMax.

◆ GetDefaultLevel()

ScalarType mitk::LevelWindow::GetDefaultLevel ( ) const

Get the default level value for the image.

Returns
The default level value.

◆ GetDefaultLowerBound()

ScalarType mitk::LevelWindow::GetDefaultLowerBound ( ) const

Get the default lower bound (default range minimum).

Returns
The default lower bound.

◆ GetDefaultUpperBound()

ScalarType mitk::LevelWindow::GetDefaultUpperBound ( ) const

Get the default upper bound (default range maximum).

Returns
The default upper bound.

◆ GetDefaultWindow()

ScalarType mitk::LevelWindow::GetDefaultWindow ( ) const

Get the default window size for the image.

Returns
The default window size.

◆ GetFixed()

bool mitk::LevelWindow::GetFixed ( ) const

Return whether the level window settings are fixed.

Returns
True if fixed, false otherwise.
See also
SetFixed

◆ GetLevel()

ScalarType mitk::LevelWindow::GetLevel ( ) const

Get the level value, i.e. the center of the current grey value interval.

Returns
The level (center) value.

◆ GetLowerWindowBound()

ScalarType mitk::LevelWindow::GetLowerWindowBound ( ) const

Get the lower bound of the current window.

Returns
The lower window bound.

◆ GetRange()

ScalarType mitk::LevelWindow::GetRange ( ) const

Get the total size of the grey value range (max - min).

Returns
The range size.

◆ GetRangeMax()

ScalarType mitk::LevelWindow::GetRangeMax ( ) const

Get the maximum of the valid value range.

Returns
The range maximum.

◆ GetRangeMin()

ScalarType mitk::LevelWindow::GetRangeMin ( ) const

Get the minimum of the valid value range.

Returns
The range minimum.

◆ GetUpperWindowBound()

ScalarType mitk::LevelWindow::GetUpperWindowBound ( ) const

Get the upper bound of the current window.

Returns
The upper window bound.

◆ GetWindow()

ScalarType mitk::LevelWindow::GetWindow ( ) const

Get the current window size, i.e. the width of the current grey value interval.

Returns
The window (range) size.

◆ IsFixed()

bool mitk::LevelWindow::IsFixed ( ) const

Return whether the level window settings are fixed.

Returns
True if fixed, false otherwise.
See also
SetFixed

◆ IsFloatingValues()

bool mitk::LevelWindow::IsFloatingValues ( ) const

Check whether the image uses floating-point values.

Returns
True if the image has float or double pixel type.

◆ operator!=()

virtual bool mitk::LevelWindow::operator!= ( const LevelWindow &  levWin) const
virtual

Compare two LevelWindow objects for inequality.

Parameters
[in]levWinThe LevelWindow to compare with.
Returns
True if any setting differs.

◆ operator=()

virtual LevelWindow& mitk::LevelWindow::operator= ( const LevelWindow &  levWin)
virtual

Assignment operator.

Parameters
[in]levWinThe LevelWindow to copy from.
Returns
Reference to this LevelWindow.

◆ operator==()

virtual bool mitk::LevelWindow::operator== ( const LevelWindow &  levWin) const
virtual

Compare two LevelWindow objects for equality.

Parameters
[in]levWinThe LevelWindow to compare with.
Returns
True if all settings match within epsilon tolerance.

◆ ResetDefaultLevelWindow()

void mitk::LevelWindow::ResetDefaultLevelWindow ( )

Reset the level and window to their default values.

◆ ResetDefaultRangeMinMax()

void mitk::LevelWindow::ResetDefaultRangeMinMax ( )

Reset the range min/max to the default boundaries.

◆ SetAuto()

void mitk::LevelWindow::SetAuto ( const Image *  image,
bool  tryPicTags = true,
bool  guessByCentralSlice = true,
unsigned  selectedComponent = 0 
)

Automatically set level/window to optimize image contrast.

Analyzes the image statistics (optionally from the central slice) to determine appropriate level/window settings that maximize contrast. Handles special cases like binary images, uniform images, and images with outlier values.

Parameters
[in]imageThe image to analyze.
[in]tryPicTagsCurrently unused, reserved for backward compatibility.
[in]guessByCentralSliceIf true, analyze only the central slice first for performance.
[in]selectedComponentThe image component to analyze (for multi-component images).

◆ SetDefaultBoundaries()

void mitk::LevelWindow::SetDefaultBoundaries ( ScalarType  low,
ScalarType  up 
)

Set the default lower and upper boundaries.

Parameters
[in]lowThe default lower bound.
[in]upThe default upper bound.

◆ SetDefaultLevelWindow()

void mitk::LevelWindow::SetDefaultLevelWindow ( ScalarType  level,
ScalarType  window 
)

Set the default level and window values.

Parameters
[in]levelThe default level (center) value.
[in]windowThe default window (range) size.

◆ SetFixed()

void mitk::LevelWindow::SetFixed ( bool  fixed)

Lock or unlock the level window settings.

When fixed, all Set methods will be no-ops.

Parameters
[in]fixedTrue to lock settings, false to allow modifications.

◆ SetFloatingValues()

void mitk::LevelWindow::SetFloatingValues ( bool  value)

Set whether the image uses floating-point values.

Parameters
[in]valueTrue for floating-point images, false otherwise.

◆ SetLevelWindow()

void mitk::LevelWindow::SetLevelWindow ( ScalarType  level,
ScalarType  window,
bool  expandRangesIfNecessary = true 
)

Set the level and window values.

Parameters
[in]levelThe center of the grey value interval.
[in]windowThe width of the grey value interval.
[in]expandRangesIfNecessaryIf true, the range is expanded to fit the new window.

◆ SetRangeMinMax()

void mitk::LevelWindow::SetRangeMinMax ( ScalarType  min,
ScalarType  max 
)

Set the minimum and maximum of the valid value range.

Parameters
[in]minThe range minimum.
[in]maxThe range maximum.

◆ SetToImageRange()

void mitk::LevelWindow::SetToImageRange ( const Image *  image)

Set level/window to the full min/max grey value range of the given image.

Parameters
[in]imageThe image whose value range determines the level/window.

◆ SetToMaxWindowSize()

void mitk::LevelWindow::SetToMaxWindowSize ( )

Set the window to cover the entire valid range.

◆ SetWindowBounds()

void mitk::LevelWindow::SetWindowBounds ( ScalarType  lowerBound,
ScalarType  upperBound,
bool  expandRangesIfNecessary = true 
)

Set the lower and upper window bounds directly.

Values are clamped to the range [-10^300, 10^300].

Parameters
[in]lowerBoundThe lower window bound.
[in]upperBoundThe upper window bound.
[in]expandRangesIfNecessaryIf true, the range is expanded to fit the new bounds.

Member Data Documentation

◆ m_DefaultLowerBound

ScalarType mitk::LevelWindow::m_DefaultLowerBound
protected

default minimum gray value of the window

Definition at line 287 of file mitkLevelWindow.h.

◆ m_DefaultUpperBound

ScalarType mitk::LevelWindow::m_DefaultUpperBound
protected

default maximum gray value of the window

Definition at line 292 of file mitkLevelWindow.h.

◆ m_Fixed

bool mitk::LevelWindow::m_Fixed
protected

Defines whether the level window settings may be changed after initialization or not.

Definition at line 303 of file mitkLevelWindow.h.

◆ m_IsFloatingImage

bool mitk::LevelWindow::m_IsFloatingImage
protected

Image with floating values

Definition at line 297 of file mitkLevelWindow.h.

◆ m_LowerWindowBound

ScalarType mitk::LevelWindow::m_LowerWindowBound
protected

lower bound of current window

Definition at line 267 of file mitkLevelWindow.h.

◆ m_RangeMax

ScalarType mitk::LevelWindow::m_RangeMax
protected

maximum gray value of the window

Definition at line 282 of file mitkLevelWindow.h.

◆ m_RangeMin

ScalarType mitk::LevelWindow::m_RangeMin
protected

minimum gray value of the window

Definition at line 277 of file mitkLevelWindow.h.

◆ m_UpperWindowBound

ScalarType mitk::LevelWindow::m_UpperWindowBound
protected

upper bound of current window

Definition at line 272 of file mitkLevelWindow.h.


The documentation for this class was generated from the following file: