18#ifndef itkKdTreeBasedKmeansEstimator_h
19#define itkKdTreeBasedKmeansEstimator_h
22#include <unordered_map>
73template <
typename TKdTree>
129 itkSetMacro(MaximumIteration,
int);
130 itkGetConstMacro(MaximumIteration,
int);
135 itkSetMacro(CentroidPositionChangesThreshold,
double);
136 itkGetConstMacro(CentroidPositionChangesThreshold,
double);
148 itkGetConstMacro(CurrentIteration,
int);
149 itkGetConstMacro(CentroidPositionChanges,
double);
160 itkSetMacro(UseClusterLabels,
bool);
161 itkGetConstMacro(UseClusterLabels,
bool);
162 itkBooleanMacro(UseClusterLabels);
197 return static_cast<int>(m_Candidates.size());
206 m_Candidates.resize(centroids.size());
207 for (
unsigned int i = 0; i < centroids.size(); ++i)
214 m_Candidates[i] = candidate;
225 centroids.resize(this->
Size());
226 for (i = 0; i < static_cast<unsigned int>(this->
Size()); ++i)
228 centroids[i] = m_Candidates[i].Centroid;
239 for (i = 0; i < static_cast<unsigned int>(this->
Size()); ++i)
241 if (m_Candidates[i].
Size > 0)
243 for (j = 0; j < m_MeasurementVectorSize; ++j)
245 m_Candidates[i].Centroid[j] =
246 m_Candidates[i].WeightedCentroid[j] /
static_cast<double>(m_Candidates[i].Size);
287 std::vector<int> validIndexes,
312 int m_CurrentIteration{ 0 };
315 int m_MaximumIteration{ 100 };
318 double m_CentroidPositionChanges{ 0.0 };
322 double m_CentroidPositionChangesThreshold{ 0.0 };
337 bool m_UseClusterLabels{
false };
338 bool m_GenerateClusterLabels{
false };
346#ifndef ITK_MANUAL_INSTANTIATION
347# include "itkKdTreeBasedKmeansEstimator.hxx"
Control indentation during Print() invocation.
Light weight base class for most itk classes.
static unsigned int GetLength()
static void SetLength(T &m, const unsigned int s)
Base class for most ITK classes.
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
DistanceToCentroidMembershipFunction models class membership using a distance metric.
void SetCentroids(InternalParametersType ¢roids)
CandidateVector()=default
std::vector< Candidate > m_Candidates
void GetCentroids(InternalParametersType ¢roids)
virtual ~CandidateVector()=default
Candidate & operator[](int index)
fast k-means algorithm implementation using k-d tree structure
typename TKdTree::InstanceIdentifier InstanceIdentifier
typename TKdTree::SampleType SampleType
void CopyParameters(InternalParametersType &source, ParametersType &target)
typename MembershipFunctionType::ConstPointer MembershipFunctionPointer
KdTreeBasedKmeansEstimator()
int GetClosestCandidate(ParameterType &measurements, std::vector< int > &validIndexes)
std::vector< ParameterType > InternalParametersType
void CopyParameters(InternalParametersType &source, InternalParametersType &target)
const MembershipFunctionVectorObjectType * GetOutput() const
std::vector< MembershipFunctionPointer > MembershipFunctionVectorType
void PrintPoint(ParameterType &point)
typename MembershipFunctionVectorObjectType::Pointer MembershipFunctionVectorObjectPointer
bool IsFarther(ParameterType &pointA, ParameterType &pointB, MeasurementVectorType &lowerBound, MeasurementVectorType &upperBound)
void FillClusterLabels(KdTreeNodeType *node, int closestIndex)
void CopyParameters(ParametersType &source, InternalParametersType &target)
void Filter(KdTreeNodeType *node, std::vector< int > validIndexes, MeasurementVectorType &lowerBound, MeasurementVectorType &upperBound)
const TKdTree * GetKdTree() const
typename TKdTree::MeasurementType MeasurementType
std::unordered_map< InstanceIdentifier, unsigned int > ClusterLabelsType
typename DistanceToCentroidMembershipFunctionType::Pointer DistanceToCentroidMembershipFunctionPointer
~KdTreeBasedKmeansEstimator() override=default
void PrintSelf(std::ostream &os, Indent indent) const override
double GetSumOfSquaredPositionChanges(InternalParametersType &previous, InternalParametersType ¤t)
typename KdTreeNodeType::CentroidType CentroidType
typename TKdTree::KdTreeNodeType KdTreeNodeType
void SetKdTree(TKdTree *tree)
typename TKdTree::MeasurementVectorType MeasurementVectorType
void GetPoint(ParameterType &point, MeasurementVectorType measurements)
unsigned int MeasurementVectorSizeType
MembershipFunctionBase defines common interfaces for membership functions.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
*par Constraints *The filter image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
Represent a n-dimensional size (bounds) of a n-dimensional image.
CentroidType WeightedCentroid