ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkAttributeMorphologyBaseImageFilter.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 itkAttributeMorphologyBaseImageFilter_h
19#define itkAttributeMorphologyBaseImageFilter_h
20
22#include <vector>
23#include <memory> // For unique_ptr.
24
25namespace itk
26{
50
51template <typename TInputImage, typename TOutputImage, typename TAttribute, typename TFunction>
52class ITK_TEMPLATE_EXPORT AttributeMorphologyBaseImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
53{
54public:
60
64 using typename Superclass::InputImagePointer;
65
70 using OutputPixelType = typename TOutputImage::PixelType;
71 using OutputInternalPixelType = typename TOutputImage::InternalPixelType;
72 using InputPixelType = typename TInputImage::PixelType;
73 using InputInternalPixelType = typename TInputImage::InternalPixelType;
74 using IndexType = typename TInputImage::IndexType;
75 using OffsetType = typename TInputImage::OffsetType;
76 using SizeType = typename TInputImage::SizeType;
77
78 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
79
83 using InputImageType = TInputImage;
84 using OutputImageType = TOutputImage;
85 // using IndexType = typename TInputImage::IndexType;
86 // using SizeType = typename TInputImage::SizeType;
87 using RegionType = typename TOutputImage::RegionType;
88 using ListType = std::list<IndexType>;
89 using AttributeType = TAttribute;
90
96
100 itkOverrideGetNameOfClassMacro(AttributeMorphologyBaseImageFilter);
101
105 itkNewMacro(Self);
106
113 itkSetMacro(FullyConnected, bool);
114 itkGetConstReferenceMacro(FullyConnected, bool);
115 itkBooleanMacro(FullyConnected);
116
122 itkSetMacro(Lambda, AttributeType);
123 itkGetConstMacro(Lambda, AttributeType);
124
125protected:
130
133 void
134 PrintSelf(std::ostream & os, Indent indent) const override;
135
139 void
140 GenerateData() override;
141
145 void
147
152 void
153 EnlargeOutputRequestedRegion(DataObject * itkNotUsed(output)) override;
154
156
157private:
160
161 // some constants used several times in the code
162 static constexpr OffsetValueType INACTIVE = -1;
163 static constexpr OffsetValueType ACTIVE = -2;
164
165 // Just used for area/volume openings at the moment
166 std::unique_ptr<AttributeType[]> m_AuxData;
167
168 using OffsetVecType = std::vector<OffsetType>;
169 // offset in the linear array.
170 using OffsetDirectVecType = std::vector<OffsetValueType>;
171
172 void
174
175 // m_SortPixels contains offsets into the raw image
176 // it is sorted with a stable sort by grey level as the
177 // first step in the algorithm. The sorting step avoids
178 // the need to explicitly locate regional extrema.
179 std::unique_ptr<OffsetValueType[]> m_SortPixels;
180 std::unique_ptr<OffsetValueType[]> m_Parent;
181
182 // This is a bit ugly, but I can't see an easy way around
183 std::unique_ptr<InputPixelType[]> m_Raw;
184
186 {
187 public:
188 TFunction m_TFunction;
189 // buf contains the raw data, which is what
190 // we want to sort by. i.e. the first value in
191 // the sorted buffer will be the location of the
192 // largest or smallest pixel.
194 bool
195 operator()(const OffsetValueType & l, const OffsetValueType & r) const
196 {
197 return (m_TFunction(buf[l], buf[r]));
198 }
199 };
200
201 CompareOffsetType m_CompareOffset{};
202 // version from PAMI. Note - using the AuxData array rather than the
203 // parent array to store area
204 void
210
213 {
214 if (m_Parent[x] >= 0)
215 {
216 m_Parent[x] = FindRoot(m_Parent[x]);
217 return (m_Parent[x]);
218 }
219 else
220 {
221 return (x);
222 }
223 }
224
225 bool
227 {
228 return ((m_Raw[x] == m_Raw[y]) || (m_AuxData[x] < m_Lambda));
229 }
230
231 void
233 {
235
236 if (r != p)
237 {
238 if (Criterion(r, p))
239 {
240 m_AuxData[p] += m_AuxData[r];
241 m_Parent[r] = p;
242 }
243 else
244 {
245 m_AuxData[p] = m_Lambda;
246 }
247 }
248 }
249};
250} // end namespace itk
251
252#ifndef ITK_MANUAL_INSTANTIATION
253# include "itkAttributeMorphologyBaseImageFilter.hxx"
254#endif
255
256#endif
bool operator()(const OffsetValueType &l, const OffsetValueType &r) const
void EnlargeOutputRequestedRegion(DataObject *output) override
void PrintSelf(std::ostream &os, Indent indent) const override
void SetupOffsetVec(OffsetDirectVecType &PosOffsets, OffsetVecType &Offsets)
bool Criterion(OffsetValueType x, OffsetValueType y)
~AttributeMorphologyBaseImageFilter() override=default
Base class for all data objects in ITK.
typename InputImageType::Pointer InputImagePointer
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition itkIntTypes.h:97