Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkAdaptiveThresholdIterator.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 itkAdaptiveThresholdIterator_h
14 #define itkAdaptiveThresholdIterator_h
15 
16 #include <itkConditionalConstIterator.h>
17 #include <itkImage.h>
18 #include <itkIndex.h>
19 #include <itkSize.h>
20 
21 #include <map>
22 #include <queue>
23 #include <utility>
24 #include <vector>
25 
26 namespace itk
27 {
33  template <class TImage, class TFunction>
34  class ITK_EXPORT AdaptiveThresholdIterator : public ConditionalConstIterator<TImage>
35  {
36  public:
39 
40  typedef ConditionalConstIterator<TImage> Superclass;
41 
42  typedef TImage ImageType;
43 
44  // A temporary image used for storing info about all indices
45  typedef TImage TTempImage;
46 
47  typename TTempImage::Pointer tempPtr;
48  //[!] isn't really used?!
49 
51  typedef TFunction FunctionType;
52 
54  typedef typename TFunction::InputType FunctionInputType;
55 
57  typedef typename TImage::SizeType SizeType;
58 
60  typedef typename TImage::RegionType RegionType;
61 
62  typedef typename TImage::IndexType IndexType;
63 
65  typedef typename TImage::InternalPixelType InternalPixelType;
66 
68  typedef typename TImage::PixelType PixelType;
69 
71  typedef std::queue<IndexType> IndexQueueType;
72 
74  typedef std::map<unsigned int, IndexQueueType> QueueMapType;
75 
80  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
81 
86 
90  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, std::vector<IndexType> &startIndex);
91 
96 
99 
102 
105 
109  void SetExpansionDirection(bool upwards);
110 
113 
117  void SetMinTH(int min);
118 
122  void SetMaxTH(int max);
123 
125  int GetSeedPointValue(void);
126 
128  void SetFineDetectionMode(bool fine = false)
129  {
130  m_FineDetectionMode = fine;
131  m_DetectionStop = false;
132  }
133 
138  const IndexType GetIndex() override
139  {
140  return (*m_QueueMap.find(m_RegionGrowingState)).second.front();
141  } // [!] is never called?!
142 
144  const PixelType Get(void) const override
145  {
146  return const_cast<ImageType *>(this->m_Image.GetPointer())
147  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front());
148  }
149 
151  void Set(const PixelType &value)
152  {
153  const_cast<ImageType *>(this->m_Image.GetPointer())
154  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front()) = value;
155  }
156 
158  void GoToBegin();
159 
161  bool IsAtEnd() const override { return this->m_IsAtEnd; };
162 
164  void operator++() override { this->DoExtendedFloodStep(); }
165 
167  virtual SmartPointer<FunctionType> GetFunction() const { return m_Function; }
170  Self &operator=(const Self &it)
171  {
172  this->m_Image = it.m_Image; // copy the smart pointer
173  this->m_Region = it.m_Region;
174  this->m_InitializeValue = it.m_InitializeValue;
175  this->m_RegionGrowingState = it.m_RegionGrowingState;
176  this->m_MinTH = it.m_MinTH;
177  this->m_MaxTH = it.m_MaxTH;
178  this->m_SeedPointValue = it.m_SeedPointValue;
179  this->m_VoxelCounter = it.m_VoxelCounter;
180  this->m_LastVoxelNumber = it.m_LastVoxelNumber;
181  this->m_DetectedLeakagePoint = it.m_DetectedLeakagePoint;
182  this->m_CurrentLeakageRatio = it.m_CurrentLeakageRatio;
183  return *this;
184  }
185 
187  bool IsPixelIncluded(const IndexType &index) const override;
188 
194  static int CalculateInitializeValue(int lower, int upper) { return ((upper - lower) + 1) * (-1); };
195 
197  int GetLeakagePoint(void) { return m_DetectedLeakagePoint; }
198  protected:
201 
203 
205  std::vector<IndexType> m_StartIndices;
206 
208  typename ImageType::PointType m_ImageOrigin;
209 
211  typename ImageType::SpacingType m_ImageSpacing;
212 
215 
217 
219 
222 
225 
228 
231 
233  unsigned int CalculateMaxRGS();
234 
235  private:
236  void InsertIndexTypeIntoQueueMap(unsigned int key, IndexType index);
237 
238  int m_RegionGrowingState;
239 
240  QueueMapType m_QueueMap;
241 
242  int m_MinTH;
243 
244  int m_MaxTH;
245 
246  int m_SeedPointValue;
247 
248  unsigned int m_VoxelCounter;
249  unsigned int m_LastVoxelNumber;
250 
251  int m_DetectedLeakagePoint;
252  float m_CurrentLeakageRatio;
253 
254  void CheckSeedPointValue();
255 
256  /* flag for switching between raw leakage detection (bigger bronchial vessels)
257  * and fine leakage detection (smaller bronchial vessels [starting from leaves])
258  */
259  bool m_FineDetectionMode;
260  bool m_DetectionStop;
261  };
262 } // end namespace itk
263 
264 #ifndef ITK_MANUAL_INSTANTIATION
265 #include <itkAdaptiveThresholdIterator.tpp>
266 #endif
267 
268 #endif
Iterates over an image using a variable image function, which threshold can be varied during the iter...
TImage::InternalPixelType InternalPixelType
void SetExpansionDirection(bool upwards)
Set the expansion direction for adaptive thresholding.
unsigned int CalculateMaxRGS()
Calculate the maximum number of region growing expansion steps.
bool IsAtEnd() const override
Check whether the iterator has reached the end of the region.
int GetSeedPointValue(void)
Get the pixel value at the seed point.
void IncrementRegionGrowingState()
Increment the region growing state counter.
itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension)
SmartPointer< FunctionType > m_Function
AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex)
void operator++() override
Walk forward one index by performing an extended flood step.
std::map< unsigned int, IndexQueueType > QueueMapType
SmartPointer< ImageType > m_OutputImage
Pointer to the output image to which the result shall be written.
int GetLeakagePoint(void)
Get the detected leakage point in the region growing state space.
void ExpandThresholdUpwards()
Expand the threshold range upwards by one step.
void DoExtendedFloodStep()
Advance the iterator by one step of the extended flood fill.
void ExpandThresholdDownwards()
Expand the threshold range downwards by one step.
AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, std::vector< IndexType > &startIndex)
void InitializeIterator()
Initialize the iterator, called from constructor.
void SetMinTH(int min)
Set the minimum threshold value.
bool IsPixelIncluded(const IndexType &index) const override
Compute whether the pixel at the given index should be included in the flood fill.
void Set(const PixelType &value)
Set the pixel value at the current iterator position.
void GoToBegin()
Reset the iterator to the beginning.
static int CalculateInitializeValue(int lower, int upper)
Calculate the initialization value for the output image based on threshold range.
const PixelType Get(void) const override
Get the pixel value at the current iterator position.
~AdaptiveThresholdIterator() override
Default Destructor.
void SetMaxTH(int max)
Set the maximum threshold value.
int EstimateDistance(IndexType)
Estimate the distance (in expansion steps) of a voxel from the current state.
void InitRegionGrowingState()
Initialize the region growing state machine.
virtual SmartPointer< FunctionType > GetFunction() const
Get the function used for threshold evaluation.
ConditionalConstIterator< TImage > Superclass
AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr)