Medical Imaging Interaction Toolkit  2024.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 {
36  template <class TImage, class TFunction>
37  class ITK_EXPORT AdaptiveThresholdIterator : public ConditionalConstIterator<TImage>
38  {
39  public:
42 
43  typedef ConditionalConstIterator<TImage> Superclass;
44 
45  typedef TImage ImageType;
46 
47  // A temporary image used for storing info about all indices
48  typedef TImage TTempImage;
49 
50  typename TTempImage::Pointer tempPtr;
51  //[!] isn't really used?!
52 
54  typedef TFunction FunctionType;
55 
57  typedef typename TFunction::InputType FunctionInputType;
58 
60  typedef typename TImage::SizeType SizeType;
61 
63  typedef typename TImage::RegionType RegionType;
64 
65  typedef typename TImage::IndexType IndexType;
66 
68  typedef typename TImage::InternalPixelType InternalPixelType;
69 
71  typedef typename TImage::PixelType PixelType;
72 
74  typedef std::queue<IndexType> IndexQueueType;
75 
77  typedef std::map<unsigned int, IndexQueueType> QueueMapType;
78 
83  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
84 
88  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex);
89 
93  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, std::vector<IndexType> &startIndex);
94 
99 
102 
104  void InitializeIterator();
105 
106  // makes the iterator go one step further
107  void DoExtendedFloodStep();
108 
109  // set-method for member-variable
110  void SetExpansionDirection(bool upwards);
111 
112  // Init-method
113  void InitRegionGrowingState();
114 
115  void SetMinTH(int min);
116 
117  void SetMaxTH(int max);
118 
119  int GetSeedPointValue(void);
120 
122  void SetFineDetectionMode(bool fine = false)
123  {
124  m_FineDetectionMode = fine;
125  m_DetectionStop = false;
126  }
127 
132  const IndexType GetIndex() override
133  {
134  return (*m_QueueMap.find(m_RegionGrowingState)).second.front();
135  } // [!] is never called?!
136 
137  const PixelType Get(void) const override
138  {
139  return const_cast<ImageType *>(this->m_Image.GetPointer())
140  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front());
141  }
142  //[!] is never called?!
143 
144  void Set(const PixelType &value)
145  {
146  const_cast<ImageType *>(this->m_Image.GetPointer())
147  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front()) = value;
148  }
149 
150  void GoToBegin();
151 
153  bool IsAtEnd() const override { return this->m_IsAtEnd; };
155  void operator++() override { this->DoExtendedFloodStep(); }
156  virtual SmartPointer<FunctionType> GetFunction() const { return m_Function; }
159  Self &operator=(const Self &it)
160  {
161  this->m_Image = it.m_Image; // copy the smart pointer
162  this->m_Region = it.m_Region;
163  this->m_InitializeValue = it.m_InitializeValue;
164  this->m_RegionGrowingState = it.m_RegionGrowingState;
165  this->m_MinTH = it.m_MinTH;
166  this->m_MaxTH = it.m_MaxTH;
167  this->m_SeedPointValue = it.m_SeedPointValue;
168  this->m_VoxelCounter = it.m_VoxelCounter;
169  this->m_LastVoxelNumber = it.m_LastVoxelNumber;
170  this->m_DetectedLeakagePoint = it.m_DetectedLeakagePoint;
171  this->m_CurrentLeakageRatio = it.m_CurrentLeakageRatio;
172  return *this;
173  }
174 
176  bool IsPixelIncluded(const IndexType &index) const override;
177 
178  // Calculate the value the outputImage is initialized to
179  static int CalculateInitializeValue(int lower, int upper) { return ((upper - lower) + 1) * (-1); };
180  int GetLeakagePoint(void) { return m_DetectedLeakagePoint; }
181  protected:
182  /*
183  * @brief Pointer on the output image to which the result shall be written
184  */
186 
188 
190  std::vector<IndexType> m_StartIndices;
191 
193  typename ImageType::PointType m_ImageOrigin;
194 
196  typename ImageType::SpacingType m_ImageSpacing;
197 
200 
202 
204 
205  void ExpandThresholdUpwards();
206 
207  void ExpandThresholdDownwards();
208 
209  void IncrementRegionGrowingState();
210 
211  // calculates how many steps the voxel is from the current step
212  int EstimateDistance(IndexType);
213 
214  // calculates how many expansion steps will be taken
215  unsigned int CalculateMaxRGS();
216 
217  private:
218  void InsertIndexTypeIntoQueueMap(unsigned int key, IndexType index);
219 
220  int m_RegionGrowingState;
221 
222  QueueMapType m_QueueMap;
223 
224  int m_MinTH;
225 
226  int m_MaxTH;
227 
228  int m_SeedPointValue;
229 
230  unsigned int m_VoxelCounter;
231  unsigned int m_LastVoxelNumber;
232 
233  int m_DetectedLeakagePoint;
234  float m_CurrentLeakageRatio;
235 
236  void CheckSeedPointValue();
237 
238  /* flag for switching between raw leakage detection (bigger bronchial vessels)
239  * and fine leakage detection (smaller bronchial vessels [starting from leaves])
240  */
241  bool m_FineDetectionMode;
242  bool m_DetectionStop;
243  };
244 } // end namespace itk
245 
246 #ifndef ITK_MANUAL_INSTANTIATION
247 #include "itkAdaptiveThresholdIterator.txx"
248 #endif
249 
250 #endif
itk::AdaptiveThresholdIterator::IndexQueueType
std::queue< IndexType > IndexQueueType
Definition: itkAdaptiveThresholdIterator.h:74
itk::AdaptiveThresholdIterator::Superclass
ConditionalConstIterator< TImage > Superclass
Definition: itkAdaptiveThresholdIterator.h:43
itk::AdaptiveThresholdIterator::GetLeakagePoint
int GetLeakagePoint(void)
Definition: itkAdaptiveThresholdIterator.h:180
itk::AdaptiveThresholdIterator::ImageType
TImage ImageType
Definition: itkAdaptiveThresholdIterator.h:45
itk::AdaptiveThresholdIterator::m_InitializeValue
int m_InitializeValue
Definition: itkAdaptiveThresholdIterator.h:203
itk::AdaptiveThresholdIterator::~AdaptiveThresholdIterator
~AdaptiveThresholdIterator() override
Definition: itkAdaptiveThresholdIterator.h:101
itk::AdaptiveThresholdIterator::SizeType
TImage::SizeType SizeType
Definition: itkAdaptiveThresholdIterator.h:60
itk::AdaptiveThresholdIterator::FunctionType
TFunction FunctionType
Definition: itkAdaptiveThresholdIterator.h:54
itk::SmartPointer< FunctionType >
itk::AdaptiveThresholdIterator::GetIndex
const IndexType GetIndex() override
Definition: itkAdaptiveThresholdIterator.h:132
itk::AdaptiveThresholdIterator::tempPtr
TTempImage::Pointer tempPtr
Definition: itkAdaptiveThresholdIterator.h:50
itk::AdaptiveThresholdIterator::SetFineDetectionMode
void SetFineDetectionMode(bool fine=false)
Definition: itkAdaptiveThresholdIterator.h:122
itk::AdaptiveThresholdIterator::FunctionInputType
TFunction::InputType FunctionInputType
Definition: itkAdaptiveThresholdIterator.h:57
itk::AdaptiveThresholdIterator::Self
AdaptiveThresholdIterator Self
Definition: itkAdaptiveThresholdIterator.h:41
itk::AdaptiveThresholdIterator::operator=
Self & operator=(const Self &it)
Definition: itkAdaptiveThresholdIterator.h:159
itk::AdaptiveThresholdIterator::PixelType
TImage::PixelType PixelType
Definition: itkAdaptiveThresholdIterator.h:71
itk::AdaptiveThresholdIterator::RegionType
TImage::RegionType RegionType
Definition: itkAdaptiveThresholdIterator.h:63
itk::AdaptiveThresholdIterator::m_OutputImage
SmartPointer< ImageType > m_OutputImage
Definition: itkAdaptiveThresholdIterator.h:185
itk::AdaptiveThresholdIterator::m_UpwardsExpansion
bool m_UpwardsExpansion
Definition: itkAdaptiveThresholdIterator.h:201
itk::AdaptiveThresholdIterator::m_Function
SmartPointer< FunctionType > m_Function
Definition: itkAdaptiveThresholdIterator.h:187
itk::AdaptiveThresholdIterator::InternalPixelType
TImage::InternalPixelType InternalPixelType
Definition: itkAdaptiveThresholdIterator.h:68
itk::AdaptiveThresholdIterator::IsAtEnd
bool IsAtEnd() const override
Definition: itkAdaptiveThresholdIterator.h:153
itk::AdaptiveThresholdIterator::m_StartIndices
std::vector< IndexType > m_StartIndices
Definition: itkAdaptiveThresholdIterator.h:190
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
itk::AdaptiveThresholdIterator::operator++
void operator++() override
Definition: itkAdaptiveThresholdIterator.h:155
itk::AdaptiveThresholdIterator::GetFunction
virtual SmartPointer< FunctionType > GetFunction() const
Definition: itkAdaptiveThresholdIterator.h:156
itk::AdaptiveThresholdIterator::QueueMapType
std::map< unsigned int, IndexQueueType > QueueMapType
Definition: itkAdaptiveThresholdIterator.h:77
itk::AdaptiveThresholdIterator::IndexType
TImage::IndexType IndexType
Definition: itkAdaptiveThresholdIterator.h:65
itk::AdaptiveThresholdIterator::CalculateInitializeValue
static int CalculateInitializeValue(int lower, int upper)
Definition: itkAdaptiveThresholdIterator.h:179
itk::AdaptiveThresholdIterator::m_ImageRegion
RegionType m_ImageRegion
Definition: itkAdaptiveThresholdIterator.h:199
itk::AdaptiveThresholdIterator::Get
const PixelType Get(void) const override
Definition: itkAdaptiveThresholdIterator.h:137
itk::AdaptiveThresholdIterator
Iterates over an image using a variable image function, which threshold can be varied during the iter...
Definition: itkAdaptiveThresholdIterator.h:37
itk::AdaptiveThresholdIterator::m_ImageSpacing
ImageType::SpacingType m_ImageSpacing
Definition: itkAdaptiveThresholdIterator.h:196
itk::AdaptiveThresholdIterator::Set
void Set(const PixelType &value)
Definition: itkAdaptiveThresholdIterator.h:144
itk::AdaptiveThresholdIterator::m_ImageOrigin
ImageType::PointType m_ImageOrigin
Definition: itkAdaptiveThresholdIterator.h:193
itk::AdaptiveThresholdIterator::TTempImage
TImage TTempImage
Definition: itkAdaptiveThresholdIterator.h:48