ITK  4.13.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  {
34  }
35 
37 
38  inline void AddBoundary() {}
39 
40  inline void RemoveBoundary() {}
41 
42  typedef std::map< TInputPixel, SizeValueType > MapType;
43 
44  inline void AddPixel(const TInputPixel & p)
45  {
46  m_Map[p]++;
47  }
48 
49  inline void RemovePixel(const TInputPixel & p)
50  {
51  m_Map[p]--;
52  }
53 
54  inline TInputPixel GetValue(const TInputPixel &)
55  {
56  return GetValue();
57  }
58 
59  inline TInputPixel GetValue()
60  {
61  // clean the map
62  typename MapType::iterator mapIt = m_Map.begin();
63  while ( mapIt != m_Map.end() )
64  {
65  if ( mapIt->second == 0 )
66  {
67  // this value must be removed from the histogram
68  // The value must be stored and the iterator updated before removing the
69  // value
70  // or the iterator is invalidated.
71  TInputPixel toErase = mapIt->first;
72  mapIt++;
73  m_Map.erase(toErase);
74  }
75  else
76  {
77  mapIt++;
78  }
79  }
80 
81  // and return the value
82  if( !m_Map.empty() )
83  {
84  return m_Map.rbegin()->first - m_Map.begin()->first;
85  }
86  return 0;
87  }
88 
90  {
91  return false;
92  }
93 
95 };
96 
97 
98 template< typename TInputPixel >
100 {
101 public:
103  {
104  // initialize members need for the vector based algorithm
108  m_Count = 0;
109  }
110 
112 
113  inline void AddBoundary() {}
114 
115  inline void RemoveBoundary() {}
116 
117 
118  inline void AddPixel(const TInputPixel & p)
119  {
120  m_Vector[p - NumericTraits < TInputPixel > ::NonpositiveMin()]++;
121  if ( p > m_Max )
122  {
123  m_Max = p;
124  }
125  if ( p < m_Min )
126  {
127  m_Min = p;
128  }
129  m_Count++;
130  }
131 
132  inline void RemovePixel(const TInputPixel & p)
133  {
134  m_Vector[p - NumericTraits < TInputPixel > ::NonpositiveMin()]--;
135  m_Count--;
136  if ( m_Count > 0 )
137  {
139  {
140  m_Max--;
141  }
143  {
144  m_Min++;
145  }
146  }
147  else
148  {
151  }
152  }
153 
154  inline TInputPixel GetValue(const TInputPixel &)
155  {
156  return GetValue();
157  }
158 
159  inline TInputPixel GetValue()
160  {
161  if ( m_Count > 0 )
162  {
163  return m_Max - m_Min;
164  }
165  else
166  {
168  }
169  }
170 
172  {
173  return true;
174  }
175 
176  std::vector< SizeValueType > m_Vector;
177  TInputPixel m_Min;
178  TInputPixel m_Max;
180 };
181 
183 
184 // now create MorphologicalGradientHistogram specilizations using the VectorMorphologicalGradientHistogram
185 // as base class
186 
187 template<>
188 class MorphologicalGradientHistogram<unsigned char>:
189  public VectorMorphologicalGradientHistogram<unsigned char>
190 {
191 };
192 
193 template<>
194 class MorphologicalGradientHistogram<signed char>:
195  public VectorMorphologicalGradientHistogram<signed char>
196 {
197 };
198 
199 template<>
200 class MorphologicalGradientHistogram<bool>:
201  public VectorMorphologicalGradientHistogram<bool>
202 {
203 };
204 
206 
207 } // end namespace Function
208 
224 template< typename TInputImage, typename TOutputImage, typename TKernel >
226  public MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel,
227  typename Function::MorphologicalGradientHistogram< typename TInputImage::
228  PixelType > >
229 {
230 public:
233  typedef MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel,
234  typename Function::MorphologicalGradientHistogram< typename TInputImage::
235  PixelType > > Superclass;
238 
240  itkNewMacro(Self);
241 
245 
247  typedef TInputImage InputImageType;
248  typedef TOutputImage OutputImageType;
249  typedef typename TInputImage::RegionType RegionType;
250  typedef typename TInputImage::SizeType SizeType;
252  typedef typename TInputImage::PixelType PixelType;
253  typedef typename TInputImage::OffsetType OffsetType;
255  typedef typename TOutputImage::PixelType OutputPixelType;
256 
258 
260  itkStaticConstMacro(ImageDimension, unsigned int,
261  TInputImage::ImageDimension);
262 
267 
268 protected:
271 
272 private:
273  ITK_DISALLOW_COPY_AND_ASSIGN(MovingHistogramMorphologicalGradientImageFilter);
274 }; // end of class
275 } // end namespace itk
276 
277 #endif
Implements a generic moving histogram algorithm.
Base class for all process objects that output image data.
Morphological gradients enhance the variation of pixel intensity in a given neighborhood.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
static ITK_CONSTEXPR_FUNC T max(const T &)
Superclass::OutputImageRegionType OutputImageRegionType
static ITK_CONSTEXPR_FUNC T NonpositiveMin()
Base class for filters that take an image as input and produce an image as output.
MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel, typename Function::MorphologicalGradientHistogram< typename TInputImage::PixelType > > Superclass
Define additional traits for native types such as int or float.