コード例 #1
0
ファイル: Slic.cpp プロジェクト: fderue/Slic
void Slic::generateSpx(Mat & frame)
{
	resetVariables();
	Mat frameLab;
	cvtColor(frame, frameLab, CV_BGR2Lab);
	frameLab.convertTo(frameLab, CV_32FC3);
	//initializa clusters
	int diamSpx_d2 = m_diamSpx / 2;
	for (int y = diamSpx_d2 - 1; y < m_height; y += m_diamSpx)
	{
		//Vec3f* frameLab_r = frameLab.ptr<Vec3f>(y);
		for (int x = diamSpx_d2 - 1; x < m_width; x += m_diamSpx)
		{
			center c;
			c.xy = Point(x, y);
			Vec3f cLab;
			moveToLowGrad(c.xy, cLab, frameLab);
			c.Lab[0] = cLab[0];
			c.Lab[1] = cLab[1];
			c.Lab[2] = cLab[2];

			m_allCenters.push_back(c);
		}
	}
	m_nSpx = (int)m_allCenters.size(); //real number of spx

	// iterate
	for (int it = 0; it < m_nIteration; it++)
	{
		findCenters(frameLab);
		updateCenters(frameLab);
	}
	//enforceConnectivity();
}
コード例 #2
0
ファイル: albedoCluster.cpp プロジェクト: winmad/mitsuba
	void kMeans() {
		int now = 0;
		int iter = 0;
		while (1) {
			assignCluster(now);
			updateCenters(now);

			// converged?
			bool flag = true;
			for (int i = 0; i < numClusters; i++) {
				if (dist2(centers[1 - now][i], centers[now][i]) > 1e-8) {
					flag = false;
					break;
				}
			}

			iter++;
			now = 1 - now;
			Log(EInfo, "====== Iter %d ======", iter);
			for (int i = 0; i < numClusters; i++) {
				//Log(EInfo, "old center %d, (%.8f, %.8f, %.8f)", i, centers[1 - now][i].x, centers[1 - now][i].y, centers[1 - now][i].z);
				Log(EInfo, "center %d, (%.8f, %.8f, %.8f)", i, centers[now][i].x, centers[now][i].y, centers[now][i].z);
			}

			if (iter > 100 || flag)
				break;
		}
	}
コード例 #3
0
ファイル: KMeans.cpp プロジェクト: AlexanderFabisch/OpenANN
Transformer& KMeans::fit(const Eigen::MatrixXd& X)
{
  OPENANN_CHECK_EQUALS(X.cols(), D);

  if(!initialized)
    initialize(X);

  OPENANN_CHECK_EQUALS(X.rows(), clusterIndices.size());

  findClusters(X);
  updateCenters(X);
  return *this;
}
コード例 #4
0
void VertexBasedSegmenter::Segmentation(){

    placeSeeds(0);
    expansionStep();
    cout<<"Reg "<<regionCentroids.size()<<endl;
    int iterNumber = 0;

    cout<<"Initialized, now start loop..."<<endl;
    while(updateCenters() && iterNumber<20){
        expansionStep();
        cout<<"Done iteration "<<iterNumber++<<"..."<<endl;
    }

    cout<<"Ok, converged (regions "<<regionCentroids.size()<<")"<<endl;
}