Ejemplo n.º 1
0
int
main(int argc, char **argv) {
    printf
            ("------------------------------------------------------------------------\n");
    if (argc != 2) {
        printf("USAGE: fcm <input file>\n");
        exit(1);
    }
    fcm(argv[1]);
    printf("Number of data points: %d\n", num_data_points);
    printf("Number of clusters: %d\n", num_clusters);
    printf("Number of data-point dimensions: %d\n", num_dimensions);
    printf("Accuracy margin: %lf\n", epsilon);
    print_membership_matrix("membership.matrix");
    gnuplot_membership_matrix();
    printf
            ("------------------------------------------------------------------------\n");
    printf("The program run was successful...\n");
    printf("Storing membership matrix in file 'membership.matrix'\n\n");
    printf("If the points are on a plane (2 dimensions)\n");
    printf("the gnuplot script was generated in file 'gnuplot.script', and\n");
    printf("the gnuplot data in files cluster.[0]... \n\n");
    printf
            ("Process 'gnuplot.script' to generate graph: 'cluster_plot.png'\n\n");
    printf
            ("NOTE: While generating the gnuplot data, for each of the data points\n");
    printf("the corresponding cluster is the one which has the highest\n");
    printf("degree-of-membership as found in 'membership.matrix'.\n");
    printf
            ("------------------------------------------------------------------------\n");
    return 0;
}
Ejemplo n.º 2
0
void PFCM::Init()
{
    //Инициализация массива номеров кластеров для каждого пикселя
    _PixelLabels = new int*[_Width];
    for (int i=0; i < _Width; i++)
    {
        _PixelLabels[i] = new int[_Height];
    }

    FCM fcm(_ClusterCount,
            _Pixels,
            _Width,
            _Height,
            _DegreeMF,
            _MaxIterationCount,
            _Precision);

    if (_ClusterCenters == NULL)
    {
        fcm.FindClusterCenters();
        _ClusterCenters = fcm.ClusterCenters();
    }
    else
    {
        fcm.SetClusterCenters(_ClusterCenters);
    }

    _BandWidth = new double[_ClusterCount];

    for (int k=0; k<_ClusterCount; k++)
    {
        double numerator=0;
        double denominator=0;

        for (int i=0; i<_Width; i++)
        {
            for (int j=0; j<_Height; j++)
            {
                double mf = pow(fcm.MembershipFunction(k,i,j),_DegreeMF);

                numerator+=mf*pow(fcm.Distance(k,i,j),2);
                denominator+=mf;
            }
        }

        _BandWidth[k]=sqrt(numerator/denominator);
    }
}
Ejemplo n.º 3
0
void 	exit(int status)
{
	int i;
	void (*fcm)(void);

	for ( i = (__UNIX_exitcount - 1); i >= 0; i -- )
	      {
	         fcm = __UNIX_exitfuncs[ i ];
			 fcm();
	      }
	

	int rc;
	/*if ( os_exit( status, &rc ) == NOTIMPLEMENTED )
			os_freakout();*/
}
Ejemplo n.º 4
0
void LayoutTest::testFeatureCollector(const cv::Mat & src) const {
	
	rdf::Timer dt;

	// parse xml
	PageXmlParser parser;
	parser.read(mConfig.xmlPath());

	// test loading of label lookup
	LabelManager lm = LabelManager::read(mConfig.featureCachePath());
	qInfo().noquote() << lm.toString();

	// compute super pixels
	SuperPixel sp(src);

	if (!sp.compute())
		qCritical() << "could not compute super pixels!";

	// feed the label lookup
	SuperPixelLabeler spl(sp.getMserBlobs(), Rect(src));
	spl.setLabelManager(lm);

	// set the ground truth
	if (parser.page())
		spl.setRootRegion(parser.page()->rootRegion());

	if (!spl.compute())
		qCritical() << "could not compute SuperPixel labeling!";

	SuperPixelFeature spf(src, spl.set());
	if (!spf.compute())
		qCritical() << "could not compute SuperPixel features!";

	FeatureCollectionManager fcm(spf.features(), spf.set());
	fcm.write(spl.config()->featureFilePath());
	
	FeatureCollectionManager testFcm = FeatureCollectionManager::read(spl.config()->featureFilePath());

	for (int idx = 0; idx < testFcm.collection().size(); idx++) {

		if (testFcm.collection()[idx].label() != fcm.collection()[idx].label())
			qWarning() << "wrong labels!" << testFcm.collection()[idx].label() << "vs" << fcm.collection()[idx].label();
		else
			qInfo() << testFcm.collection()[idx].label() << "is fine...";
	}

	// drawing
	cv::Mat rImg = src.clone();

	// save super pixel image
	//rImg = superPixel.drawSuperPixels(rImg);
	//rImg = tabStops.draw(rImg);
	rImg = spl.draw(rImg);
	rImg = spf.draw(rImg);
	QString dstPath = rdf::Utils::instance().createFilePath(mConfig.outputPath(), "-textlines");
	rdf::Image::save(rImg, dstPath);
	qDebug() << "debug image saved: " << dstPath;

	qDebug() << "image path: " << mConfig.imagePath();

}