ITK  6.0.0
Insight Toolkit
itkMovingHistogramMorphologicalGradientImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMovingHistogramMorphologicalGradientImageFilter_h
19 #define itkMovingHistogramMorphologicalGradientImageFilter_h
20 
22 #include <map>
23 
24 namespace itk
25 {
26 namespace Function
27 {
28 template <typename TInputPixel>
30 {
31 public:
33 
35 
36  inline void
38  {}
39 
40  inline void
42  {}
43 
44  using MapType = std::map<TInputPixel, SizeValueType>;
45 
46  inline void
47  AddPixel(const TInputPixel & p)
48  {
49  m_Map[p]++;
50  }
51 
52  inline void
53  RemovePixel(const TInputPixel & p)
54  {
55  m_Map[p]--;
56  }
57 
58  inline TInputPixel
59  GetValue(const TInputPixel &)
60  {
61  return GetValue();
62  }
63 
64  inline TInputPixel
66  {
67  // clean the map
68  typename MapType::iterator mapIt = m_Map.begin();
69  while (mapIt != m_Map.end())
70  {
71  if (mapIt->second == 0)
72  {
73  // this value must be removed from the histogram
74  // The value must be stored and the iterator updated before removing the
75  // value
76  // or the iterator is invalidated.
77  TInputPixel toErase = mapIt->first;
78  ++mapIt;
79  m_Map.erase(toErase);
80  }
81  else
82  {
83  ++mapIt;
84  }
85  }
86 
87  // and return the value
88  if (!m_Map.empty())
89  {
90  return m_Map.rbegin()->first - m_Map.begin()->first;
91  }
92  return 0;
93  }
94 
95  static bool
97  {
98  return false;
99  }
100 
102 };
103 
104 
105 template <typename TInputPixel>
107 {
108 public:
110  {
111  // initialize members need for the vector based algorithm
115  m_Count = 0;
116  }
117 
119 
120  inline void
122  {}
123 
124  inline void
126  {}
127 
128 
129  inline void
130  AddPixel(const TInputPixel & p)
131  {
133  if (p > m_Max)
134  {
135  m_Max = p;
136  }
137  if (p < m_Min)
138  {
139  m_Min = p;
140  }
141  ++m_Count;
142  }
143 
144  inline void
145  RemovePixel(const TInputPixel & p)
146  {
148  --m_Count;
149  if (m_Count > 0)
150  {
152  {
153  --m_Max;
154  }
156  {
157  ++m_Min;
158  }
159  }
160  else
161  {
164  }
165  }
166 
167  inline TInputPixel
168  GetValue(const TInputPixel &)
169  {
170  return GetValue();
171  }
172 
173  inline TInputPixel
175  {
176  if (m_Count > 0)
177  {
178  return m_Max - m_Min;
179  }
180  else
181  {
182  return TInputPixel{};
183  }
184  }
185 
186  static bool
188  {
189  return true;
190  }
191 
192  std::vector<SizeValueType> m_Vector;
193  TInputPixel m_Min;
194  TInputPixel m_Max;
196 };
197 
199 
200 // now create MorphologicalGradientHistogram specializations using the VectorMorphologicalGradientHistogram
201 // as base class
202 
203 template <>
204 class MorphologicalGradientHistogram<unsigned char> : public VectorMorphologicalGradientHistogram<unsigned char>
205 {};
206 
207 template <>
208 class MorphologicalGradientHistogram<signed char> : public VectorMorphologicalGradientHistogram<signed char>
209 {};
210 
211 template <>
212 class ITK_TEMPLATE_EXPORT MorphologicalGradientHistogram<bool> : public VectorMorphologicalGradientHistogram<bool>
213 {};
214 
216 
217 } // end namespace Function
218 
234 template <typename TInputImage, typename TOutputImage, typename TKernel>
237  TInputImage,
238  TOutputImage,
239  TKernel,
240  typename Function::MorphologicalGradientHistogram<typename TInputImage::PixelType>>
241 {
242 public:
243  ITK_DISALLOW_COPY_AND_MOVE(MovingHistogramMorphologicalGradientImageFilter);
244 
247  using Superclass =
248  MovingHistogramImageFilter<TInputImage,
249  TOutputImage,
250  TKernel,
254 
256  itkNewMacro(Self);
257 
259  itkOverrideGetNameOfClassMacro(MovingHistogramMorphologicalGradientImageFilter);
260 
262  using InputImageType = TInputImage;
263  using OutputImageType = TOutputImage;
265  using SizeType = typename TInputImage::SizeType;
267  using PixelType = typename TInputImage::PixelType;
268  using OffsetType = typename TInputImage::OffsetType;
269  using typename Superclass::OutputImageRegionType;
270  using OutputPixelType = typename TOutputImage::PixelType;
271 
273 
275  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
276 
279  static bool
281  {
283  }
284 
285 protected:
288 }; // end of class
289 } // end namespace itk
290 
291 #endif
itk::Function::VectorMorphologicalGradientHistogram::RemoveBoundary
void RemoveBoundary()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:125
itk::BoxImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkBoxImageFilter.h:67
itk::MovingHistogramMorphologicalGradientImageFilter::~MovingHistogramMorphologicalGradientImageFilter
~MovingHistogramMorphologicalGradientImageFilter() override=default
itk::Function::VectorMorphologicalGradientHistogram::m_Count
SizeValueType m_Count
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:195
itk::Function::MorphologicalGradientHistogram::m_Map
MapType m_Map
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:101
itk::Function::MorphologicalGradientHistogram::GetValue
TInputPixel GetValue()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:65
itk::MovingHistogramMorphologicalGradientImageFilter::MovingHistogramMorphologicalGradientImageFilter
MovingHistogramMorphologicalGradientImageFilter()=default
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:99
itk::Function::MorphologicalGradientHistogram
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:29
itk::Function::VectorMorphologicalGradientHistogram::AddPixel
void AddPixel(const TInputPixel &p)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:130
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::Function::VectorMorphologicalGradientHistogram::UseVectorBasedAlgorithm
static bool UseVectorBasedAlgorithm()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:187
itk::Function::VectorMorphologicalGradientHistogram::GetValue
TInputPixel GetValue(const TInputPixel &)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:168
itk::SmartPointer< Self >
itk::Function::MorphologicalGradientHistogram::RemovePixel
void RemovePixel(const TInputPixel &p)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:53
itk::Function::VectorMorphologicalGradientHistogram::GetValue
TInputPixel GetValue()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:174
itk::BoxImageFilter::OffsetType
typename TInputImage::OffsetType OffsetType
Definition: itkBoxImageFilter.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::BoxImageFilter::IndexType
typename TInputImage::IndexType IndexType
Definition: itkBoxImageFilter.h:61
itk::MovingHistogramImageFilterBase::PixelType
typename TInputImage::PixelType PixelType
Definition: itkMovingHistogramImageFilterBase.h:114
itk::MovingHistogramMorphologicalGradientImageFilter::ImageDimension
static constexpr unsigned int ImageDimension
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:275
itk::MovingHistogramMorphologicalGradientImageFilter
Morphological gradients enhance the variation of pixel intensity in a given neighborhood.
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:235
itk::Function::MorphologicalGradientHistogram::UseVectorBasedAlgorithm
static bool UseVectorBasedAlgorithm()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:96
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::Function::MorphologicalGradientHistogram::AddBoundary
void AddBoundary()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:37
itk::Function::VectorMorphologicalGradientHistogram
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:106
itk::Function::MorphologicalGradientHistogram::GetValue
TInputPixel GetValue(const TInputPixel &)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:59
itk::Function::MorphologicalGradientHistogram::RemoveBoundary
void RemoveBoundary()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:41
itk::Function::VectorMorphologicalGradientHistogram::~VectorMorphologicalGradientHistogram
~VectorMorphologicalGradientHistogram()=default
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:169
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::Function::VectorMorphologicalGradientHistogram::RemovePixel
void RemovePixel(const TInputPixel &p)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:145
itk::Function::VectorMorphologicalGradientHistogram::m_Vector
std::vector< SizeValueType > m_Vector
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:192
itk::MovingHistogramImageFilter
Implements a generic moving histogram algorithm.
Definition: itkMovingHistogramImageFilter.h:88
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itkMovingHistogramImageFilter.h
itk::BoxImageFilter::SizeType
typename TInputImage::SizeType SizeType
Definition: itkBoxImageFilter.h:60
itk::Function::MorphologicalGradientHistogram::AddPixel
void AddPixel(const TInputPixel &p)
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:47
itk::Function::MorphologicalGradientHistogram::MapType
std::map< TInputPixel, SizeValueType > MapType
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:44
itk::Function::VectorMorphologicalGradientHistogram::AddBoundary
void AddBoundary()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:121
itk::Function::VectorMorphologicalGradientHistogram::VectorMorphologicalGradientHistogram
VectorMorphologicalGradientHistogram()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:109
itk::Function::MorphologicalGradientHistogram::~MorphologicalGradientHistogram
~MorphologicalGradientHistogram()=default
itk::Function::MorphologicalGradientHistogram::MorphologicalGradientHistogram
MorphologicalGradientHistogram()=default
itk::Function::VectorMorphologicalGradientHistogram::m_Max
TInputPixel m_Max
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:194
itk::Function::VectorMorphologicalGradientHistogram::m_Min
TInputPixel m_Min
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:193
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::BoxImageFilter::RegionType
typename TInputImage::RegionType RegionType
Definition: itkBoxImageFilter.h:59
itk::MovingHistogramMorphologicalGradientImageFilter::GetUseVectorBasedAlgorithm
static bool GetUseVectorBasedAlgorithm()
Definition: itkMovingHistogramMorphologicalGradientImageFilter.h:280