ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
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:
117
119
120 inline void
122 {}
123
124 inline void
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
181 return TInputPixel{};
182 }
183
184 static bool
186 {
187 return true;
188 }
189
190 std::vector<SizeValueType> m_Vector;
191 TInputPixel m_Min;
192 TInputPixel m_Max;
194};
195
197
198// now create MorphologicalGradientHistogram specializations using the VectorMorphologicalGradientHistogram
199// as base class
200
201template <>
202class MorphologicalGradientHistogram<unsigned char> : public VectorMorphologicalGradientHistogram<unsigned char>
203{};
204
205template <>
206class MorphologicalGradientHistogram<signed char> : public VectorMorphologicalGradientHistogram<signed char>
207{};
208
209template <>
210class ITK_TEMPLATE_EXPORT MorphologicalGradientHistogram<bool> : public VectorMorphologicalGradientHistogram<bool>
211{};
212
214
215} // end namespace Function
216
229
230template <typename TInputImage, typename TOutputImage, typename TKernel>
233 TInputImage,
234 TOutputImage,
235 TKernel,
236 typename Function::MorphologicalGradientHistogram<typename TInputImage::PixelType>>
237{
238public:
239 ITK_DISALLOW_COPY_AND_MOVE(MovingHistogramMorphologicalGradientImageFilter);
240
244 MovingHistogramImageFilter<TInputImage,
245 TOutputImage,
246 TKernel,
250
252 itkNewMacro(Self);
253
255 itkOverrideGetNameOfClassMacro(MovingHistogramMorphologicalGradientImageFilter);
256
258 using InputImageType = TInputImage;
259 using OutputImageType = TOutputImage;
260 using RegionType = typename TInputImage::RegionType;
261 using SizeType = typename TInputImage::SizeType;
262 using IndexType = typename TInputImage::IndexType;
263 using PixelType = typename TInputImage::PixelType;
264 using OffsetType = typename TInputImage::OffsetType;
266 using OutputPixelType = typename TOutputImage::PixelType;
267
269
271 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
272
275 static bool
280
281protected:
284}; // end of class
285} // end namespace itk
286
287#endif
typename OutputImageType::RegionType OutputImageRegionType
MovingHistogramImageFilter< TInputImage, TOutputImage, TKernel, typename Function::MorphologicalGradientHistogram< typename TInputImage::PixelType > > Superclass
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86