ITK  5.4.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
24namespace itk
25{
26namespace Function
27{
28template <typename TInputPixel>
30{
31public:
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
105template <typename TInputPixel>
107{
108public:
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
203template <>
204class MorphologicalGradientHistogram<unsigned char> : public VectorMorphologicalGradientHistogram<unsigned char>
205{};
206
207template <>
208class MorphologicalGradientHistogram<signed char> : public VectorMorphologicalGradientHistogram<signed char>
209{};
210
211template <>
212class ITK_TEMPLATE_EXPORT MorphologicalGradientHistogram<bool> : public VectorMorphologicalGradientHistogram<bool>
213{};
214
216
217} // end namespace Function
218
234template <typename TInputImage, typename TOutputImage, typename TKernel>
237 TInputImage,
238 TOutputImage,
239 TKernel,
240 typename Function::MorphologicalGradientHistogram<typename TInputImage::PixelType>>
241{
242public:
243 ITK_DISALLOW_COPY_AND_MOVE(MovingHistogramMorphologicalGradientImageFilter);
244
248 MovingHistogramImageFilter<TInputImage,
249 TOutputImage,
250 TKernel,
254
256 itkNewMacro(Self);
257
259 itkOverrideGetNameOfClassMacro(MovingHistogramMorphologicalGradientImageFilter);
260
262 using InputImageType = TInputImage;
263 using OutputImageType = TOutputImage;
267 using PixelType = typename TInputImage::PixelType;
268 using OffsetType = typename TInputImage::OffsetType;
270 using OutputPixelType = typename TOutputImage::PixelType;
271
273
275 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
276
279 static bool
281 {
283 }
284
285protected:
288}; // end of class
289} // end namespace itk
290
291#endif
typename TInputImage::RegionType RegionType
typename TInputImage::SizeType SizeType
typename TInputImage::IndexType IndexType
typename TOutputImage::PixelType OutputPixelType
typename TInputImage::OffsetType OffsetType
Base class for all process objects that output image data.
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
Implements a generic moving histogram algorithm.
Morphological gradients enhance the variation of pixel intensity in a given neighborhood.
Define additional traits for native types such as int or float.
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:83