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 
28 #include "itkMinimumDecisionRule.h"
29 
31 
32 #include <vector>
33 
34 namespace itk
35 {
64 template <typename TInputImage, typename TOutputImage = Image<unsigned char, TInputImage::ImageDimension>>
65 class ITK_TEMPLATE_EXPORT ScalarImageKmeansImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
66 {
67 public:
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
126  AddClassWithInitialMean(RealPixelType mean);
127 
129  itkGetConstReferenceMacro(FinalMeans, ParametersType);
130 
136  itkSetMacro(UseNonContiguousLabels, bool);
137  itkGetConstReferenceMacro(UseNonContiguousLabels, bool);
138  itkBooleanMacro(UseNonContiguousLabels);
142  void
143  SetImageRegion(const ImageRegionType & region);
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 
154 protected:
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 
173 private:
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
itk::Statistics::DistanceToCentroidMembershipFunction
DistanceToCentroidMembershipFunction models class membership using a distance metric.
Definition: itkDistanceToCentroidMembershipFunction.h:45
itk::ScalarImageKmeansImageFilter::MeasurementVectorType
typename AdaptorType::MeasurementVectorType MeasurementVectorType
Definition: itkScalarImageKmeansImageFilter.h:100
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Statistics::WeightedCentroidKdTreeGenerator
This class generates a KdTree object with centroid information.
Definition: itkWeightedCentroidKdTreeGenerator.h:67
itk::ScalarImageKmeansImageFilter::MembershipFunctionVectorType
typename ClassifierType::MembershipFunctionVectorType MembershipFunctionVectorType
Definition: itkScalarImageKmeansImageFilter.h:108
itkSampleClassifierFilter.h
itk::Statistics::KdTree
This class provides methods for k-nearest neighbor search and related data structures for a k-d tree.
Definition: itkKdTree.h:527
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:716
itk::ScalarImageKmeansImageFilter
Classifies the intensity values of a scalar image using the K-Means algorithm.
Definition: itkScalarImageKmeansImageFilter.h:65
itk::ScalarImageKmeansImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkScalarImageKmeansImageFilter.h:90
itk::Statistics::DistanceToCentroidMembershipFunction::CentroidType
typename DistanceMetricType::OriginType CentroidType
Definition: itkDistanceToCentroidMembershipFunction.h:76
itk::ScalarImageKmeansImageFilter::ParametersType
typename EstimatorType::ParametersType ParametersType
Definition: itkScalarImageKmeansImageFilter.h:118
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::Statistics::ImageToListSampleAdaptor
This class provides ListSample interface to ITK Image.
Definition: itkImageToListSampleAdaptor.h:54
itk::ScalarImageKmeansImageFilter::MembershipFunctionPointer
typename MembershipFunctionType::Pointer MembershipFunctionPointer
Definition: itkScalarImageKmeansImageFilter.h:111
itk::ScalarImageKmeansImageFilter::ClassLabelVectorType
typename ClassifierType::ClassLabelVectorType ClassLabelVectorType
Definition: itkScalarImageKmeansImageFilter.h:106
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkKdTreeBasedKmeansEstimator.h
itk::ScalarImageKmeansImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkScalarImageKmeansImageFilter.h:91
itk::Statistics::ImageToListSampleAdaptor::MeasurementVectorType
typename MeasurementPixelTraitsType::MeasurementVectorType MeasurementVectorType
Definition: itkImageToListSampleAdaptor.h:92
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itkMinimumDecisionRule.h
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::Statistics::KdTreeBasedKmeansEstimator
fast k-means algorithm implementation using k-d tree structure
Definition: itkKdTreeBasedKmeansEstimator.h:74
itk::ScalarImageKmeansImageFilter::RealPixelType
typename NumericTraits< InputPixelType >::RealType RealPixelType
Definition: itkScalarImageKmeansImageFilter.h:94
itk::ScalarImageKmeansImageFilter::MembershipFunctionOriginType
typename MembershipFunctionType::CentroidType MembershipFunctionOriginType
Definition: itkScalarImageKmeansImageFilter.h:109
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::ScalarImageKmeansImageFilter::ImageRegionType
typename InputImageType::RegionType ImageRegionType
Definition: itkScalarImageKmeansImageFilter.h:120
itkKdTree.h
itk::Statistics::SampleClassifierFilter::MembershipFunctionVectorType
std::vector< MembershipFunctionPointer > MembershipFunctionVectorType
Definition: itkSampleClassifierFilter.h:75
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itkRegionOfInterestImageFilter.h
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ScalarImageKmeansImageFilter::MeansContainer
std::vector< RealPixelType > MeansContainer
Definition: itkScalarImageKmeansImageFilter.h:174
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::ScalarImageKmeansImageFilter::TreeType
typename TreeGeneratorType::KdTreeType TreeType
Definition: itkScalarImageKmeansImageFilter.h:115
itk::Array< double >
itk::Statistics::SampleClassifierFilter::ClassLabelVectorType
std::vector< ClassLabelType > ClassLabelVectorType
Definition: itkSampleClassifierFilter.h:86
itk::Statistics::SampleClassifierFilter
Sample classification class.
Definition: itkSampleClassifierFilter.h:45
itk::RegionOfInterestImageFilter
Extract a region of interest from the input image.
Definition: itkRegionOfInterestImageFilter.h:54
itk::Statistics::MinimumDecisionRule
A decision rule that returns the class label with the smallest discriminant score.
Definition: itkMinimumDecisionRule.h:38
itkImageToListSampleAdaptor.h
itkWeightedCentroidKdTreeGenerator.h
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90