60 : m_LowerWindowBound(level - window / 2.0),
61 m_UpperWindowBound(level + window / 2.0),
64 m_DefaultLowerBound(-2048.0),
65 m_DefaultUpperBound(4096.0),
66 m_IsFloatingImage(false),
74 : m_LowerWindowBound(levWin.GetLowerWindowBound()),
75 m_UpperWindowBound(levWin.GetUpperWindowBound()),
76 m_RangeMin(levWin.GetRangeMin()),
77 m_RangeMax(levWin.GetRangeMax()),
78 m_DefaultLowerBound(levWin.GetDefaultLowerBound()),
79 m_DefaultUpperBound(levWin.GetDefaultUpperBound()),
80 m_IsFloatingImage(levWin.IsFloatingValues()),
81 m_Fixed(levWin.GetFixed())
91 return (m_UpperWindowBound - m_LowerWindowBound) / 2.0 + m_LowerWindowBound;
96 return (m_UpperWindowBound - m_LowerWindowBound);
101 return ((m_DefaultUpperBound + m_DefaultLowerBound) / 2.0);
106 return ((m_DefaultUpperBound - m_DefaultLowerBound));
111 SetLevelWindow(GetDefaultLevel(), GetDefaultWindow());
116 return m_LowerWindowBound;
121 return m_UpperWindowBound;
126 SetDefaultBoundaries((level - (window / 2.0)), (level + (window / 2.0)));
131 SetWindowBounds((level - (window / 2.0)), (level + (window / 2.0)), expandRangesIfNecessary);
136 bool expandRangesIfNecessary)
141 m_LowerWindowBound = lowerBound;
142 m_UpperWindowBound = upperBound;
144 if (expandRangesIfNecessary)
147 if (m_LowerWindowBound > m_UpperWindowBound)
148 std::swap(m_LowerWindowBound, m_UpperWindowBound);
149 if (m_LowerWindowBound < m_RangeMin)
151 m_RangeMin = m_LowerWindowBound;
154 if (m_UpperWindowBound > m_RangeMax)
156 m_RangeMax = m_UpperWindowBound;
176 m_DefaultLowerBound = low;
177 m_DefaultUpperBound = up;
180 if (m_DefaultLowerBound > m_DefaultUpperBound)
181 std::swap(m_DefaultLowerBound, m_DefaultUpperBound);
183 if (m_DefaultLowerBound == m_DefaultUpperBound)
184 m_DefaultLowerBound--;
191 SetWindowBounds(m_RangeMin, m_RangeMax);
206 return m_RangeMax - m_RangeMin;
211 return m_DefaultUpperBound;
216 return m_DefaultLowerBound;
221 SetRangeMinMax(m_DefaultLowerBound, m_DefaultUpperBound);
262 bool guessByCentralSlice,
263 unsigned selectedComponent)
274 m_IsFloatingImage =
true;
278 m_IsFloatingImage =
false;
287 if (guessByCentralSlice)
289 sliceSelector->SetInput(image);
292 sliceSelector->SetChannelNr(image->
GetDimension(4) / 2);
293 sliceSelector->Update();
294 image = sliceSelector->GetOutput();
302 if (minValue == maxValue)
319 for (
unsigned int i = 1; i < image->
GetDimension(3); ++i)
322 if (minValue > minValueTemp)
323 minValue = minValueTemp;
325 if (maxValue < maxValueTemp)
326 maxValue = maxValueTemp;
328 if (min2ndValue > min2ndValueTemp)
329 min2ndValue = min2ndValueTemp;
331 if (max2ndValue > max2ndValueTemp)
332 max2ndValue = max2ndValueTemp;
341 if (minValue == -(pow((
double)2.0, static_cast<int>(image->
GetPixelType().
GetBpe() / 2))))
343 minValue = min2ndValue;
349 if (minValue == maxValue)
351 minValue = maxValue - 1;
359 double additionalRange = 0.15 * (maxValue - minValue);
360 minValue -= additionalRange;
361 maxValue += additionalRange;
363 SetRangeMinMax(minValue, maxValue);
364 SetDefaultBoundaries(minValue, maxValue);
376 for (
unsigned int k = 0; k < image->
GetDimension(); ++k)
384 if (min2ndValue == maxValue)
390 else if (min2ndValue == max2ndValue)
393 minValue = min2ndValue - minDelta;
394 maxValue = min2ndValue + minDelta;
400 ScalarType innerRange = max2ndValue - min2ndValue;
402 if (minCountFraction > 0.2)
404 ScalarType halfInnerRangeGapMinValue = min2ndValue - innerRange / 2.0;
405 minValue =
std::max(minValue, halfInnerRangeGapMinValue);
409 minValue = min2ndValue;
412 if (maxCountFraction > 0.2)
414 ScalarType halfInnerRangeGapMaxValue = max2ndValue + innerRange / 2.0;
415 maxValue =
std::min(maxValue, halfInnerRangeGapMaxValue);
419 maxValue = max2ndValue;
422 SetWindowBounds(minValue, maxValue);
423 SetDefaultLevelWindow((maxValue - minValue) / 2 + minValue, maxValue - minValue);
436 SetRangeMinMax(minValue, maxValue);
437 SetDefaultBoundaries(minValue, maxValue);
438 SetWindowBounds(minValue, maxValue);
439 SetDefaultLevelWindow((maxValue - minValue) / 2 + minValue, maxValue - minValue);
459 return m_IsFloatingImage;
464 m_IsFloatingImage = value;
480 return !((*this) == levWin);
void SetWindowBounds(ScalarType lowerBound, ScalarType upperBound, bool expandRangesIfNecessary=true)
ScalarType m_DefaultLowerBound
LevelWindow(ScalarType level=127.5, ScalarType window=255.0)
ScalarType GetDefaultLevel() const
method returns the default level value for the image
ScalarType GetLowerWindowBound() const
void ResetDefaultLevelWindow()
Resets the level and the window value to the default values.
void SetFixed(bool fixed)
ScalarType m_DefaultUpperBound
void SetToImageRange(const Image *image)
sets level/window to the min/max greyvalues of the given Image
StatisticsHolderPointer GetStatistics() const
Returns a pointer to the ImageStatisticsHolder object that holds all statistics information for the i...
bool IsFloatingValues() const
Shows if floating values are accepted.
ScalarType GetDefaultWindow() const
returns the default window size for the image
virtual mitk::ScalarType GetScalarValue2ndMaxNoRecompute(unsigned int t=0)
Get the second largest value for scalar images, but do not recompute it first.
static void Update(vtkPolyData *)
itk::ImageIOBase::IOPixelType GetPixelType() const
virtual mitk::ScalarType GetScalarValue2ndMinNoRecompute(unsigned int t=0) const
Get the second smallest value for scalar images, but do not recompute it first.
virtual unsigned int GetCountOfMinValuedVoxelsNoRecompute(unsigned int t=0) const
Get the count of voxels with the smallest scalar value in the dataset.
virtual mitk::ScalarType GetScalarValueMaxNoRecompute(unsigned int t=0)
Get the largest value for scalar images, but do not recompute it first.
ScalarType GetDefaultLowerBound() const
virtual unsigned int GetCountOfMaxValuedVoxelsNoRecompute(unsigned int t=0)
Get the count of voxels with the largest scalar value in the dataset.
void SetRangeMinMax(ScalarType min, ScalarType max)
ScalarType GetDefaultUpperBound() const
The LevelWindow class Class to store level/window values.
virtual ScalarType GetScalarValueMin(int t=0, unsigned int component=0)
Get the minimum for scalar images. Recomputation performed only when necessary.
virtual LevelWindow & operator=(const LevelWindow &levWin)
implementation necessary because operator made private in itk::Object
void SetFloatingValues(bool value)
Sets the floating image value.
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
void SetDefaultLevelWindow(ScalarType level, ScalarType window)
unsigned int * GetDimensions() const
Get the sizes of all dimensions as an integer-array.
void ResetDefaultRangeMinMax()
the default min and max range for image will be reset
Image class for storing images.
void SetAuto(const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
sets level/window to optimize the contrast of the given Image
ScalarType m_UpperWindowBound
virtual bool operator!=(const LevelWindow &levWin) const
non equality operator implementation that allows to compare two level windows
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
MITKCORE_EXPORT const ScalarType sqrteps
void SetDefaultBoundaries(ScalarType low, ScalarType up)
ScalarType GetRangeMax() const
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
ScalarType m_LowerWindowBound
static void swap(T &x, T &y)
void SetToMaxWindowSize()
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
ScalarType GetRangeMin() const
virtual bool operator==(const LevelWindow &levWin) const
equality operator implementation that allows to compare two level windows
ScalarType GetUpperWindowBound() const
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
unsigned int GetDimension() const
Get dimension of the image.
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
ScalarType GetRange() const
returns the size of the grey value range
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...