ITK  6.0.0
Insight Toolkit
itkScalarImageKmeansImageFilter.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 itkScalarImageKmeansImageFilter_h
19#define itkScalarImageKmeansImageFilter_h
20
21
22#include "itkKdTree.h"
25
29
31
32#include <vector>
33
34namespace itk
35{
64template <typename TInputImage, typename TOutputImage = Image<unsigned char, TInputImage::ImageDimension>>
65class ITK_TEMPLATE_EXPORT ScalarImageKmeansImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
66{
67public:
68 ITK_DISALLOW_COPY_AND_MOVE(ScalarImageKmeansImageFilter);
69
71 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
72
74 using InputImageType = TInputImage;
75 using OutputImageType = TOutputImage;
76
82
84 itkNewMacro(Self);
85
87 itkOverrideGetNameOfClassMacro(ScalarImageKmeansImageFilter);
88
90 using InputPixelType = typename InputImageType::PixelType;
91 using OutputPixelType = typename OutputImageType::PixelType;
92
95
98
101
105
107
110
112
117
119
121
123
125 void
127
129 itkGetConstReferenceMacro(FinalMeans, ParametersType);
130
136 itkSetMacro(UseNonContiguousLabels, bool);
137 itkGetConstReferenceMacro(UseNonContiguousLabels, bool);
138 itkBooleanMacro(UseNonContiguousLabels);
142 void
144
146 itkGetConstReferenceMacro(ImageRegion, ImageRegionType);
147
148#ifdef ITK_USE_CONCEPT_CHECKING
149 // Begin concept checking
150 itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
151 // End concept checking
152#endif
153
154protected:
156 ~ScalarImageKmeansImageFilter() override = default;
157 void
158 PrintSelf(std::ostream & os, Indent indent) const override;
159
165 void
166 GenerateData() override;
167
168 /* See superclass for doxygen. This methods additionally checks that
169 * the number of means is not 0. */
170 void
171 VerifyPreconditions() const override;
172
173private:
174 using MeansContainer = std::vector<RealPixelType>;
175
176 MeansContainer m_InitialMeans{};
177
178 ParametersType m_FinalMeans{};
179
180 bool m_UseNonContiguousLabels{ false };
181
182 ImageRegionType m_ImageRegion{};
183
184 bool m_ImageRegionDefined{ false };
185};
186} // end namespace itk
187
188#ifndef ITK_MANUAL_INSTANTIATION
189# include "itkScalarImageKmeansImageFilter.hxx"
190#endif
191
192#endif
An image region represents a structured region of data.
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
Extract a region of interest from the input image.
Classifies the intensity values of a scalar image using the K-Means algorithm.
typename EstimatorType::ParametersType ParametersType
typename InputImageType::RegionType ImageRegionType
typename TreeGeneratorType::KdTreeType TreeType
typename OutputImageType::PixelType OutputPixelType
void VerifyPreconditions() const override
Verifies that the process object has been configured correctly, that all required inputs are set,...
typename ClassifierType::MembershipFunctionVectorType MembershipFunctionVectorType
~ScalarImageKmeansImageFilter() override=default
void AddClassWithInitialMean(RealPixelType mean)
typename AdaptorType::MeasurementVectorType MeasurementVectorType
typename ClassifierType::ClassLabelVectorType ClassLabelVectorType
void PrintSelf(std::ostream &os, Indent indent) const override
typename InputImageType::PixelType InputPixelType
typename MembershipFunctionType::CentroidType MembershipFunctionOriginType
typename NumericTraits< InputPixelType >::RealType RealPixelType
void SetImageRegion(const ImageRegionType &region)
typename MembershipFunctionType::Pointer MembershipFunctionPointer
DistanceToCentroidMembershipFunction models class membership using a distance metric.
This class provides ListSample interface to ITK Image.
typename MeasurementPixelTraitsType::MeasurementVectorType MeasurementVectorType
fast k-means algorithm implementation using k-d tree structure
This class provides methods for k-nearest neighbor search and related data structures for a k-d tree.
Definition: itkKdTree.h:528
A decision rule that returns the class label with the smallest discriminant score.
std::vector< MembershipFunctionPointer > MembershipFunctionVectorType
std::vector< ClassLabelType > ClassLabelVectorType
This class generates a KdTree object with centroid information.
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....