コード例 #1
0
int Execute( int height , bool resample )
{
	StreamingGrid *in , *out , *labels=NULL;
	JointRImageSampler< LabelType , Real > *jointIn = NULL;
	int outWidth , outHeight;

	GetReadSize< Real >( In.value , outWidth , outHeight );
	if( resample )
	{
#if 1	// Try to resample using linear interpolation but without blending across the seams.
		if( Labels.set )
		{
			jointIn = new JointRImageSampler< LabelType , Real >( Labels.value , In.value , 2*height , height , true , false , 0 , NULL );
			labels = jointIn->nearestChild;
			in     = jointIn->averageChild;
		}
		else in = new RImageSampler< Real >( In.value , 2*height , height , false , true , false , 0 , NULL );
#else
		in = new RImageSampler< Real >( In.value , 2*height , height , true , true , false , 0 , NULL );
		if( Labels.set ) labels = new RImageSampler< LabelType >( Labels.value , 2*height , height , true  , true , false , 0 , NULL );
#endif
	}
	else
	{
		int w;
		in = GetReadStream< Real >( In.value , w , height , true , false , false , NULL );
		if( Labels.set ) labels = GetReadStream< LabelType >( Labels.value , w , height , true , false , false , NULL );
	}
	if( resample )
		out = new WImageSampler< Real >( Out.value , 2*height , height , outWidth , outHeight , false , false , false , false , Quality.value , NULL );
	else
		out = GetWriteStream< Real >( Out.value , 2*height , height , false , false , Quality.value , NULL );

	SphericalStencilTable< double > stencilTable;
	double t = Time();
	if( StencilIO.set )
	{
		if( !stencilTable.read( StencilIO.value ) ) fprintf( stderr , "Failed to read stencil table: %s\n" , StencilIO.value );
		if( stencilTable.Init( height , 2*height , 8 , true , true ) )
		{
			if( !stencilTable.write( StencilIO.value ) ) fprintf( stderr , "Failed to write stencil table: %s\n" , StencilIO.value );
		}
		else fprintf( stderr , "Failed to set stencil-table: %d x %d\n" , height , 2*height );
	}
	else stencilTable.Init( height , 2*height , 8 , true , true );
	printf( "Spherical Stencil Table set in: %f\n" , Time() - t );
	if( UnknownIndex.set )
	{
		LabelType unknownIndex[] = { LabelType( UnknownIndex.values[0] ) , LabelType( UnknownIndex.values[1] ) , LabelType( UnknownIndex.values[2] ) };
		StitchImage< Real , IOReal , LabelType , 3 >( height , 8 , &stencilTable , in , labels , out , Iters.value , IWeight.value , GScale.value , GWeight.value , unknownIndex );
	}
	else
		StitchImage< Real , IOReal , LabelType , 3 >( height , 8 , &stencilTable , in , labels , out , Iters.value , IWeight.value , GScale.value , GWeight.value , NULL );

	delete in;
	delete out;
	if( labels ) delete labels;
	if( jointIn ) delete jointIn;
	return EXIT_SUCCESS;
}
コード例 #2
0
//Run inference with Lazy Flipper initialized to setting in initlab
void runLazyFlipper(GraphicalModelType* gm,std::string ofname, std::string initlab, size_t subGraphsize)
{
	//Initial Labelling
	std::vector<LabelType> startPoint(gm->numberOfVariables());
	std::ifstream input;
	input.open(initlab.c_str());
	int label;
	for(size_t i=0;i<gm->numberOfVariables();i++)
	{
		input>>label;	
		startPoint[i] = LabelType(label);	
#ifdef DEBUG
		std::cout<<"L"<<i<<":"<<label<<" ";
#endif
	}

	//Run Inference
	size_t maxSubgraphsize;
	if(subGraphsize<=0)
		maxSubgraphsize = gm->numberOfVariables()/2;
	else
		maxSubgraphsize = subGraphsize;
	LazyFlipper::Parameter para(maxSubgraphsize);
	LazyFlipper lf(*gm,para);
	lf.setStartingPoint(startPoint.begin());
	
	std::cout<<"Running Inference"<<std::endl;
	lf.infer();
	std::cout << "MAP Result: " << lf.value() << " Bound: "<<lf.bound()<<std::endl;
	std::vector<LabelType> result;
	lf.arg(result);
	//Write Result
	writeResult(result,ofname);
}
コード例 #3
0
//Run inference with Lazy Flipper initialized to setting in initlab
void runICM(GraphicalModelType* gm,std::string ofname, std::string initlab)
{
	//Initial Labelling
	std::vector<LabelType> startPoint(gm->numberOfVariables());
	std::ifstream input;
	input.open(initlab.c_str());
	int label;
	for(size_t i=0;i<gm->numberOfVariables();i++)
	{
		input>>label;	
		startPoint[i] = LabelType(label);	
#ifdef DEBUG
		std::cout<<"L"<<i<<":"<<label<<" ";
#endif
	}
	//Run Inference
	ICM::Parameter para(startPoint); 
	ICM icm(*gm,para);
	std::cout<<"Running Inference"<<std::endl;
	icm.infer();
	std::cout << "MAP Result: " << icm.value() << " Bound: "<<icm.bound()<<std::endl;
	std::vector<LabelType> result;
	icm.arg(result);
	//Write Result
	writeResult(result,ofname);
}