Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
mitkMinMaxLabelmageFilterWithIndex.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkMinMaxLabelmageFilterWithIndex_h
14 #define mitkMinMaxLabelmageFilterWithIndex_h
15 
17 
18 #include <itkImage.h>
19 #include <itkImageToImageFilter.h>
20 #include <itkImageRegionConstIteratorWithIndex.h>
21 #include <unordered_map>
22 
23 
24 namespace itk
25 {
26 template <typename TInputImage, typename TLabelImage>
27 class MinMaxLabelImageFilterWithIndex: public itk::ImageToImageFilter<TInputImage, TInputImage>
28 {
29 public:
32  typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
35 
37  itkNewMacro(Self);
38 
40  itkTypeMacro(MinMaxLabelImageFilterWithIndex, ImageToImageFilter);
41 
42  typedef typename TInputImage::RegionType RegionType;
43  typedef typename TInputImage::SizeType SizeType;
44  typedef typename TInputImage::IndexType IndexType;
45  typedef typename TInputImage::PixelType PixelType;
46  typedef typename NumericTraits< PixelType >::RealType RealType;
47 
48  typedef typename TLabelImage::RegionType LabelRegionType;
49  typedef typename TLabelImage::SizeType LabelSizeType;
50  typedef typename TLabelImage::IndexType LabelIndexType;
51  typedef typename TLabelImage::PixelType LabelPixelType;
52 
57  {
58  public:
61 
63  m_Min(std::numeric_limits<PixelType>::max()),
64  m_Max(std::numeric_limits<PixelType>::min())
65  {}
66  };
67 
68  typedef typename std::unordered_map<LabelPixelType, LabelExtrema> ExtremaMapType;
69  typedef typename ExtremaMapType::iterator ExtremaMapTypeIterator;
70  typedef typename ExtremaMapType::const_iterator ExtremaMapTypeConstIterator;
71  typedef typename ExtremaMapType::value_type MapValueType;
72 
74  {
75  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
76  if (it == m_LabelExtrema.end())
77  {
78  MITK_ERROR << "invalid label";
79  }
80 
81  return (*it).second.m_Min;
82  }
83 
85  {
86  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
87  if (it == m_LabelExtrema.end())
88  {
89  MITK_ERROR << "invalid label";
90  }
91 
92  return (*it).second.m_Max;
93  }
94 
98  std::vector<LabelPixelType> GetRelevantLabels() const
99  {
100  std::vector<LabelPixelType> labels;
101  for (auto&& it:m_LabelExtrema)
102  {
103  labels.push_back(it.first);
104  }
105  return labels;
106  }
107 
109  {
110  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
111  if (it == m_LabelExtrema.end())
112  {
113  MITK_ERROR << "invalid label";
114  }
115 
116  return (*it).second.m_MinIndex;
117 
118  }
119 
121  {
122  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
123  if (it == m_LabelExtrema.end())
124  {
125  MITK_ERROR << "invalid label";
126  }
127 
128  return (*it).second.m_MaxIndex;
129 
130  }
131 
133  {
134  return m_GlobalMin;
135  }
136 
138  {
139  return m_GlobalMax;
140  }
141 
143  {
144  return m_GlobalMinIndex;
145  }
146 
148  {
149  return m_GlobalMaxIndex;
150  }
151 
153  void SetLabelInput(const TLabelImage *input)
154  {
155  // Process object is not const-correct so the const casting is required.
156  this->SetNthInput( 1, const_cast< TLabelImage * >( input ) );
157  }
158 
160  const TLabelImage * GetLabelInput() const
161  {
162  return itkDynamicCastInDebugMode< TLabelImage * >( const_cast< DataObject * >( this->ProcessObject::GetInput(1) ) );
163  }
164 
165 protected:
167  {
168  this->DynamicMultiThreadingOff();
169  }
170 
171  void AllocateOutputs() override;
172 
173  void ThreadedGenerateData(const RegionType &
174  outputRegionForThread,
175  ThreadIdType threadId) override;
176 
177  void BeforeThreadedGenerateData() override;
178 
179  void AfterThreadedGenerateData() override;
180 
181 private:
182  std::vector<ExtremaMapType> m_ThreadExtrema;
183 
184  ExtremaMapType m_LabelExtrema;
185  PixelType m_GlobalMin;
186  PixelType m_GlobalMax;
187  IndexType m_GlobalMinIndex, m_GlobalMaxIndex;
188 };
189 }
190 
191 #include "mitkMinMaxLabelmageFilterWithIndex.hxx"
192 
193 
194 #endif
itk::MinMaxLabelImageFilterWithIndex::GetMinIndex
IndexType GetMinIndex(LabelPixelType label) const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:108
itk::MinMaxLabelImageFilterWithIndex::ExtremaMapType
std::unordered_map< LabelPixelType, LabelExtrema > ExtremaMapType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:68
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema::m_Max
PixelType m_Max
Definition: mitkMinMaxLabelmageFilterWithIndex.h:59
itk::MinMaxLabelImageFilterWithIndex
Definition: mitkMinMaxLabelmageFilterWithIndex.h:27
itk::MinMaxLabelImageFilterWithIndex::IndexType
TInputImage::IndexType IndexType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:44
MITK_ERROR
#define MITK_ERROR
Definition: mitkLog.h:211
itk::MinMaxLabelImageFilterWithIndex::PixelType
TInputImage::PixelType PixelType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:45
itk::MinMaxLabelImageFilterWithIndex::LabelRegionType
TLabelImage::RegionType LabelRegionType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:48
itk::MinMaxLabelImageFilterWithIndex::LabelIndexType
TLabelImage::IndexType LabelIndexType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:50
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema
The LabelExtrema class is just a container for global min/max values and their indices as well as all...
Definition: mitkMinMaxLabelmageFilterWithIndex.h:56
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema::m_MinIndex
IndexType m_MinIndex
Definition: mitkMinMaxLabelmageFilterWithIndex.h:60
itk::MinMaxLabelImageFilterWithIndex::MapValueType
ExtremaMapType::value_type MapValueType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:71
itk::SmartPointer< Self >
itk::MinMaxLabelImageFilterWithIndex::GetGlobalMax
PixelType GetGlobalMax() const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:137
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema::LabelExtrema
LabelExtrema()
Definition: mitkMinMaxLabelmageFilterWithIndex.h:62
itk::MinMaxLabelImageFilterWithIndex::AfterThreadedGenerateData
void AfterThreadedGenerateData() override
itk::MinMaxLabelImageFilterWithIndex::GetGlobalMinIndex
IndexType GetGlobalMinIndex() const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:142
itk::MinMaxLabelImageFilterWithIndex::Self
MinMaxLabelImageFilterWithIndex Self
Definition: mitkMinMaxLabelmageFilterWithIndex.h:31
itk::MinMaxLabelImageFilterWithIndex::ThreadedGenerateData
void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType threadId) override
itk::MinMaxLabelImageFilterWithIndex::Pointer
SmartPointer< Self > Pointer
Definition: mitkMinMaxLabelmageFilterWithIndex.h:33
itk::MinMaxLabelImageFilterWithIndex::Superclass
ImageToImageFilter< TInputImage, TInputImage > Superclass
Definition: mitkMinMaxLabelmageFilterWithIndex.h:32
itk::MinMaxLabelImageFilterWithIndex::RegionType
TInputImage::RegionType RegionType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:40
itk::MinMaxLabelImageFilterWithIndex::GetGlobalMin
PixelType GetGlobalMin() const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:132
itk::MinMaxLabelImageFilterWithIndex::SetLabelInput
void SetLabelInput(const TLabelImage *input)
Definition: mitkMinMaxLabelmageFilterWithIndex.h:153
itk::MinMaxLabelImageFilterWithIndex::GetRelevantLabels
std::vector< LabelPixelType > GetRelevantLabels() const
Returns a std::vector containing all labels for which min and max values (and indices) have been comp...
Definition: mitkMinMaxLabelmageFilterWithIndex.h:98
itk::MinMaxLabelImageFilterWithIndex::GetMax
PixelType GetMax(LabelPixelType label) const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:84
itk::MinMaxLabelImageFilterWithIndex::GetGlobalMaxIndex
IndexType GetGlobalMaxIndex() const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:147
itk::MinMaxLabelImageFilterWithIndex::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
itk::MinMaxLabelImageFilterWithIndex::ExtremaMapTypeIterator
ExtremaMapType::iterator ExtremaMapTypeIterator
Definition: mitkMinMaxLabelmageFilterWithIndex.h:69
itk::MinMaxLabelImageFilterWithIndex::GetMaxIndex
IndexType GetMaxIndex(LabelPixelType label) const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:120
itk::MinMaxLabelImageFilterWithIndex::SizeType
TInputImage::SizeType SizeType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:43
itk::MinMaxLabelImageFilterWithIndex::GetMin
PixelType GetMin(LabelPixelType label) const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:73
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema::m_MaxIndex
IndexType m_MaxIndex
Definition: mitkMinMaxLabelmageFilterWithIndex.h:60
itk::MinMaxLabelImageFilterWithIndex::LabelExtrema::m_Min
PixelType m_Min
Definition: mitkMinMaxLabelmageFilterWithIndex.h:59
itk::MinMaxLabelImageFilterWithIndex::ConstPointer
SmartPointer< const Self > ConstPointer
Definition: mitkMinMaxLabelmageFilterWithIndex.h:34
itk::MinMaxLabelImageFilterWithIndex::LabelPixelType
TLabelImage::PixelType LabelPixelType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:51
itk::MinMaxLabelImageFilterWithIndex::GetLabelInput
const TLabelImage * GetLabelInput() const
Definition: mitkMinMaxLabelmageFilterWithIndex.h:160
itk::MinMaxLabelImageFilterWithIndex::RealType
NumericTraits< PixelType >::RealType RealType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:46
itk::MinMaxLabelImageFilterWithIndex::MinMaxLabelImageFilterWithIndex
MinMaxLabelImageFilterWithIndex()
Definition: mitkMinMaxLabelmageFilterWithIndex.h:166
MitkImageStatisticsExports.h
itk::MinMaxLabelImageFilterWithIndex::ExtremaMapTypeConstIterator
ExtremaMapType::const_iterator ExtremaMapTypeConstIterator
Definition: mitkMinMaxLabelmageFilterWithIndex.h:70
itk::MinMaxLabelImageFilterWithIndex::AllocateOutputs
void AllocateOutputs() override
itk::MinMaxLabelImageFilterWithIndex::LabelSizeType
TLabelImage::SizeType LabelSizeType
Definition: mitkMinMaxLabelmageFilterWithIndex.h:49