/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2012 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLBlob/src/VQ2D.cpp ** ** Module : ICLBlob ** ** Authors: Christof Elbrechter, Robert Haschke ** ** ** ** ** ** Commercial License ** ** ICL can be used commercially, please refer to our website ** ** www.iclcv.org for more details. ** ** ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the ** ** GNU General Public License version 3.0 as published by the ** ** Free Software Foundation and appearing in the file LICENSE.GPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the GNU General Public License ** ** version 3.0 requirements will be met: ** ** http://www.gnu.org/copyleft/gpl.html. ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** *********************************************************************/ #include #include namespace icl{ inline float distance(float *a, float *b){ // {{{ open return sqrt( pow(a[0]-b[0],2)+pow(a[1]-b[1],2) ); } // }}} inline int nn(float *data, int dim, float* point, float &dist){ // {{{ open int bestIndex = 0; dist = distance(data,point); float currDist = -1; for(int i=1 ; idim(); float *data = m_poData->data(); m_poCenters->resize(k); float *centers = m_poCenters->data(); // check if all parameters are valid! ICLASSERT_RETURN_VAL( k>=0 ,*m_poCenters); ICLASSERT_RETURN_VAL( n>=0 ,*m_poCenters); /************************************************** ** Random initialisation of the center vectors **** >> TODO other strategy or *************************************************** give them from anywhere else */ for(int p=0 ; p vecx(k),vecy(k); // mean x/y accumulators std::vector vecn(k); // cluster size counters for(int step = 0 ; stepdim(); int n = m_poData->dim(); VQVectorSet ¢ers = *m_poCenters; VQVectorSet &data = *m_poData; VQClusterInfo &info = *m_poClusterInfo; info.resize(k); info.clear(); float err, *p; int inn; for(int i=0;i