Example #1
0
void ColorHistogramLab<Mesh>::extract(const Mesh&m,arma::vec&hist)
{
    hist = arma::vec( (NL_+ 1)*(Na_+1)*(Nb_+1) ,arma::fill::ones);

    arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true);
    arma::fmat Lab_mat;
    ColorArray::RGB2Lab(rgb_mat,Lab_mat);
    for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index )
    {
        arma::fvec Lab = Lab_mat.col(index);
        hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))] += 1.0 ;
    }
    hist /= arma::accu(hist);
    hist *= hist.size();
}
Example #2
0
void exportCenters(const std::vector<Cluster>& clusters, const std::string& imgFilename, const std::string& csvFilename)
{
    const int k = clusters.size();

    int w = (512 + k - 1) / k;
    
    std::ofstream f(csvFilename);
    cv::Mat img = cv::Mat::zeros(32, w*k, CV_8UC3);

    std::cout << "k=" << k << "\n";

    int i = 0;
    for(auto it : clusters) {
        cv::Vec3b Lab(it.color[0], it.color[1], it.color[2]);
        cv::Vec3b rgb;
        convert(Lab, rgb, CV_Lab2RGB);
        auto r = (int)rgb[0];
        auto g = (int)rgb[1];
        auto b = (int)rgb[2];

        std::cout << r << ", " << g << ", " << b << "\n";

        f << it.count << ";" << r << ";" << g << ";" << b << ";\n";

        cv::rectangle(img, cv::Rect(i * w, 0, w, 32), cv::Scalar(b, g, r), cv::FILLED);
        ++i;
    }

    cv::imwrite(imgFilename, img);
}
Example #3
0
void ColorHistogramLab<Mesh>::extract(const Mesh&m,std::vector<double>&hist)
{
    hist.resize((NL_+ 1)*(Na_+1)*(Nb_+1),1.0);
    arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true);
    arma::fmat Lab_mat;
    ColorArray::RGB2Lab(rgb_mat,Lab_mat);
    double sum = 0.0;
    for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index )
    {
        arma::fvec Lab = Lab_mat.col(index);
        hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))]+= 1.0 ;
        sum += 1.0;
    }
    #pragma omp parallel for
    for(int i=0; i<hist.size(); ++i)
    {
        hist[i] *= (hist.size()/sum);
    }
}
Example #4
0
void GrailMain (void)
	{
	ALERROR error;
	CTextOut Output;
	CLabyrinth Lab(&Output);

	//	Boot

	printf("Grail Language v1.0\n\n");

	if (error = Lab.Boot())
		{
		printf("%s\n", Lab.GetLastErrorMsg().GetASCIIZPointer());
		return;
		}

	printf("Grail ready\n\n");

	//	Command loop

	while (true)
		{
		//	Get user input

		CString sInput;
		printf(": ");
		gets(sInput.GetWritePointer(1024));
		sInput.Truncate(lstrlen(sInput.GetASCIIZPointer()));

		//	If this is the quit command, we're done

		if (strEquals(sInput, CONSTLIT("quit")))
			break;

		//	Process the command

		}

	//	Done

	Lab.Shutdown();
	printf("End session.");
	}
Example #5
0
void parser::LabState()
{
	Lab();
	State();
}