57 template<
class Vector,
class Scalar>
79 static inline Scalar
dist(
const Vector &a,
const Vector &b){
93 const std::vector<int> &
nums;
103 inline void init(
int numCenters){
106 m_nums.resize(numCenters);
111 inline int findNN(
const Vector &v, Scalar &minDist){
116 if(currDist < minDist){
127 template<
class RandomAcessIterator>
128 Result apply(RandomAcessIterator begin, RandomAcessIterator end,
int numSteps = 1000,
bool reinitCenters=
true){
132 URandI r((
int)(end-begin)-1);
139 for(
int step=0;step<numSteps;++step){
141 for(
size_t i=0;i<
m_means.size();++i){
148 for(RandomAcessIterator it=begin;it != end; ++it){
149 const int nn =
findNN(*it,minDist);
155 for(
size_t i=0;i<
m_means.size();++i){
ICLQt_API ImgQ sqrt(const ImgQ &image)
calls sqrt( each pixel)
undocument this line if you encounter any issues!
Definition: Any.h:37
#define ICLMath_API
Definition: CompatMacros.h:173
lightweight Random generator class for uniform random distributions in positive integer domain
Definition: Random.h:172
std::vector< Vector > m_centers
internal list of centroids
Definition: KMeans.h:61
KMeans(int numCenters=0)
constructor with optionally given number of centers
Definition: KMeans.h:98
static void setVectorNull(Vector &v)
sets a vector to null
Definition: KMeans.h:84
static Scalar diff_power_two(const Scalar &a, const Scalar &b)
internal utility function
Definition: KMeans.h:73
std::vector< Vector > m_means
internal buffer
Definition: KMeans.h:64
const std::vector< Scalar > & errors
average quantisation errors
Definition: KMeans.h:94
void init(int numCenters)
deferred intitialization with number of centers
Definition: KMeans.h:103
ICLQt_API void fill(float r, float g=-1, float b=-1, float alpha=255)
sets the current fill color to given r,g,b,alpha value
restult type
Definition: KMeans.h:91
int findNN(const Vector &v, Scalar &minDist)
finds the nearest centroid for a given data pointer
Definition: KMeans.h:111
static const Point32f null
null Point is x=0, y=0
Definition: Point32f.h:51
static Scalar dist(const Vector &a, const Vector &b)
utility function computing the vector distance
Definition: KMeans.h:79
Generic Implementation of the K-Means algorithm.
Definition: KMeans.h:58
const std::vector< Vector > & centers
final list of centroids
Definition: KMeans.h:92
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
float distanceTo(const Point32f &p) const
returns the euclidian distance to another point
std::vector< Scalar > m_errors
averate quantisation error for each centroid
Definition: KMeans.h:70
std::vector< int > m_nums
numbers of points associated to each centroid
Definition: KMeans.h:67
Result apply(RandomAcessIterator begin, RandomAcessIterator end, int numSteps=1000, bool reinitCenters=true)
runs the KMeans algorithms on the given data
Definition: KMeans.h:128
const std::vector< int > & nums
final number of points for each centroid
Definition: KMeans.h:93