ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMovingHistogramMorphologicalGradientImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 AddBoundary() {}
37 
38  inline void RemoveBoundary() {}
39 
40  using MapType = std::map< TInputPixel, SizeValueType >;
41 
42  inline void AddPixel(const TInputPixel & p)
43  {
44  m_Map[p]++;
45  }
46 
47  inline void RemovePixel(const TInputPixel & p)
48  {
49  m_Map[p]--;
50  }
51 
52  inline TInputPixel GetValue(const TInputPixel &)
53  {
54  return GetValue();
55  }
56 
57  inline TInputPixel GetValue()
58  {
59  // clean the map
60  typename MapType::iterator mapIt = m_Map.begin();
61  while ( mapIt != m_Map.end() )
62  {
63  if ( mapIt->second == 0 )
64  {
65  // this value must be removed from the histogram
66  // The value must be stored and the iterator updated before removing the
67  // value
68  // or the iterator is invalidated.
69  TInputPixel toErase = mapIt->first;
70  mapIt++;
71  m_Map.erase(toErase);
72  }
73  else
74  {
75  mapIt++;
76  }
77  }
78 
79  // and return the value
80  if( !m_Map.empty() )
81  {
82  return m_Map.rbegin()->first - m_Map.begin()->first;
83  }
84  return 0;
85  }
86 
88  {
89  return false;
90  }
91 
93 };
94 
95 
96 template< typename TInputPixel >
98 {
99 public:
101  {
102  // initialize members need for the vector based algorithm
106  m_Count = 0;
107  }
108 
110 
111  inline void AddBoundary() {}
112 
113  inline void RemoveBoundary() {}
114 
115 
116  inline void AddPixel(const TInputPixel & p)
117  {
118  m_Vector[p - NumericTraits < TInputPixel > ::NonpositiveMin()]++;
119  if ( p > m_Max )
120  {
121  m_Max = p;
122  }
123  if ( p < m_Min )
124  {
125  m_Min = p;
126  }
127  m_Count++;
128  }
129 
130  inline void RemovePixel(const TInputPixel & p)
131  {
132  m_Vector[p - NumericTraits < TInputPixel > ::NonpositiveMin()]--;
133  m_Count--;
134  if ( m_Count > 0 )
135  {
137  {
138  m_Max--;
139  }
141  {
142  m_Min++;
143  }
144  }
145  else
146  {
149  }
150  }
151 
152  inline TInputPixel GetValue(const TInputPixel &)
153  {
154  return GetValue();
155  }
156 
157  inline TInputPixel GetValue()
158  {
159  if ( m_Count > 0 )
160  {
161  return m_Max - m_Min;
162  }
163  else
164  {
166  }
167  }
168 
170  {
171  return true;
172  }
173 
174  std::vector< SizeValueType > m_Vector;
175  TInputPixel m_Min;
176  TInputPixel m_Max;
178 };
179 
181 
182 // now create MorphologicalGradientHistogram specilizations using the VectorMorphologicalGradientHistogram
183 // as base class
184 
185 template<>
186 class MorphologicalGradientHistogram<unsigned char>:
187  public VectorMorphologicalGradientHistogram<unsigned char>
188 {
189 };
190 
191 template<>
192 class MorphologicalGradientHistogram<signed char>:
193  public VectorMorphologicalGradientHistogram<signed char>
194 {
195 };
196 
197 template<>
198 class MorphologicalGradientHistogram<bool>:
199  public VectorMorphologicalGradientHistogram<bool>
200 {
201 };
202 
204 
205 } // end namespace Function
206 
222 template< typename TInputImage, typename TOutputImage, typename TKernel >
224  public MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel,
225  typename Function::MorphologicalGradientHistogram< typename TInputImage::
226  PixelType > >
227 {
228 public:
229  ITK_DISALLOW_COPY_AND_ASSIGN(MovingHistogramMorphologicalGradientImageFilter);
230 
233  using Superclass = MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel,
234  typename Function::MorphologicalGradientHistogram< typename TInputImage::
235  PixelType > >;
238 
240  itkNewMacro(Self);
241 
245 
247  using InputImageType = TInputImage;
248  using OutputImageType = TOutputImage;
250  using SizeType = typename TInputImage::SizeType;
252  using PixelType = typename TInputImage::PixelType;
253  using OffsetType = typename TInputImage::OffsetType;
255  using OutputPixelType = typename TOutputImage::PixelType;
256 
258 
260  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
261 
266 
267 protected:
270 }; // end of class
271 } // end namespace itk
272 
273 #endif
Define numeric traits for std::vector.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename TInputImage::IndexType IndexType
Implements a generic moving histogram algorithm.
typename TOutputImage::PixelType OutputPixelType
typename TInputImage::RegionType RegionType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
Morphological gradients enhance the variation of pixel intensity in a given neighborhood.
typename TInputImage::OffsetType OffsetType
typename OutputImageType::RegionType OutputImageRegionType
typename TInputImage::SizeType SizeType
TOutputImage OutputImageType
Base class for filters that take an image as input and produce an image as output.
typename Superclass::OutputImageRegionType OutputImageRegionType