ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkScalarImageKmeansImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 {
62 template< typename TInputImage,
63  typename TOutputImage = Image< unsigned char, TInputImage::ImageDimension > >
64 class ITK_TEMPLATE_EXPORT ScalarImageKmeansImageFilter:
65  public ImageToImageFilter< TInputImage, TOutputImage >
66 {
67 public:
68  ITK_DISALLOW_COPY_AND_ASSIGN(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 
88 
90  using InputPixelType = typename InputImageType::PixelType;
91  using OutputPixelType = typename OutputImageType::PixelType;
92 
95 
98 
101 
105 
107 
110 
112 
117 
119 
121 
125 
127  void AddClassWithInitialMean(RealPixelType mean);
128 
130  itkGetConstReferenceMacro(FinalMeans, ParametersType);
131 
137  itkSetMacro(UseNonContiguousLabels, bool);
138  itkGetConstReferenceMacro(UseNonContiguousLabels, bool);
139  itkBooleanMacro(UseNonContiguousLabels);
141 
143  void SetImageRegion(const ImageRegionType & region);
144 
146  itkGetConstReferenceMacro(ImageRegion, ImageRegionType);
147 
148 #ifdef ITK_USE_CONCEPT_CHECKING
149  // Begin concept checking
150  itkConceptMacro( InputHasNumericTraitsCheck,
152  // End concept checking
153 #endif
154 
155 protected:
157  ~ScalarImageKmeansImageFilter() override = default;
158  void PrintSelf(std::ostream & os, Indent indent) const override;
159 
165  void GenerateData() override;
166 
167  /* See superclass for doxygen. This methods additionally checks that
168  * the number of means is not 0. */
169  void VerifyPreconditions() ITKv5_CONST override;
170 
171 private:
172  using MeansContainer = std::vector< RealPixelType >;
173 
174  MeansContainer m_InitialMeans;
175 
176  ParametersType m_FinalMeans;
177 
178  bool m_UseNonContiguousLabels{ false };
179 
181 
182  bool m_ImageRegionDefined{ false };
183 };
184 } // end namespace itk
185 
186 #ifndef ITK_MANUAL_INSTANTIATION
187 #include "itkScalarImageKmeansImageFilter.hxx"
188 #endif
189 
190 #endif
typename MembershipFunctionType::Pointer MembershipFunctionPointer
Define numeric traits for std::vector.
typename OutputImageType::PixelType OutputPixelType
fast k-means algorithm implementation using k-d tree structure
std::vector< ClassLabelType > ClassLabelVectorType
An image region represents a structured region of data.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
typename InputImageType::RegionType ImageRegionType
A decision rule that returns the class label with the smallest discriminant score.
typename EstimatorType::ParametersType ParametersType
typename MembershipFunctionType::CentroidType MembershipFunctionOriginType
This class generates a KdTree object with centroid information.
typename ClassifierType::ClassLabelVectorType ClassLabelVectorType
TOutputImage OutputImageType
typename InputImageType::PixelType InputPixelType
typename NumericTraits< InputPixelType >::RealType RealPixelType
Classifies the intensity values of a scalar image using the K-Means algorithm.
typename AdaptorType::MeasurementVectorType MeasurementVectorType
typename ClassifierType::MembershipFunctionVectorType MembershipFunctionVectorType
Extract a region of interest from the input image.
DistanceToCentroidMembershipFunction models class membership using a distance metric.
typename MeasurementPixelTraitsType::MeasurementVectorType MeasurementVectorType
Base class for filters that take an image as input and produce an image as output.
std::vector< MembershipFunctionPointer > MembershipFunctionVectorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
This class provides ListSample interface to ITK Image.
#define itkConceptMacro(name, concept)
typename TreeGeneratorType::KdTreeType TreeType