当前位置: 首页>>代码示例>>C++>>正文


C++ Energy::add_term1方法代码示例

本文整理汇总了C++中Energy::add_term1方法的典型用法代码示例。如果您正苦于以下问题:C++ Energy::add_term1方法的具体用法?C++ Energy::add_term1怎么用?C++ Energy::add_term1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Energy的用法示例。


在下文中一共展示了Energy::add_term1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: expandOnLabel

void expandOnLabel(int label,int width,int height,int num_pixels,
				   vector<int> &Seeds,int numSeeds, vector<int> &labeling,
				   vector<Value> &horizWeights,vector<Value> &vertWeights,Value lambda,
				   vector<Value> &diag1Weights,vector<Value> &diag2Weights,int PATCH_SIZE,
				   vector<int> &changeMask, vector<int> &changeMaskNew,image<uchar> *I,
				   int TYPE,float variance)
{
	int seedX,seedY,startX,startY,endX,endY,numVars,blockWidth;
	getBounds(width,height,Seeds,&seedX,&seedY,&startX,&startY,&endX,&endY,label,PATCH_SIZE);

	int somethingChanged = 0;

	for ( int y = startY; y <= endY; y++ )
		for ( int x = startX; x <= endX; x++ )
			if ( changeMask[x+y*width] == 1 )
			{
				somethingChanged = 1;
				break;
			}

	
	if ( somethingChanged == 0)
		return;
		
	blockWidth = endX-startX+1;
	numVars   = (endY-startY+1)*blockWidth;
	

	vector<Var> variables(numVars);
	Energy<int,int,int> *e = new Energy<int,int,int>(numVars,numVars*3);

	for ( int i = 0; i < numVars; i++ )
		variables[i] = e->add_variable();

	Value LARGE_WEIGHT = lambda*NUM_COLORS*8;

	// First fix the border to old labels, except the edges of the image
	for ( int y = startY; y <= endY; y++ ){
		if ( startX != 0 )
			e->add_term1(variables[(y-startY)*blockWidth],0,LARGE_WEIGHT);
		else if ( y == startY || y == endY)
			e->add_term1(variables[(y-startY)*blockWidth],0,LARGE_WEIGHT);

		if( endX != width -1 )
			e->add_term1(variables[(endX-startX)+(y-startY)*blockWidth],0,LARGE_WEIGHT);
		else if ( y == startY || y == endY)
			e->add_term1(variables[(endX-startX)+(y-startY)*blockWidth],0,LARGE_WEIGHT);
	}

	for ( int x = startX+1; x < endX; x++){
		if ( startY != 0 )
			e->add_term1(variables[(x-startX)],0,LARGE_WEIGHT);
		if ( endY != height - 1)
			e->add_term1(variables[(x-startX)+(endY-startY)*blockWidth],0,LARGE_WEIGHT);
	}

	// add links to center of the patch for color constant superpixels
	if ( TYPE == 1 )
	{
		int color = imRef(I,seedX,seedY);

		for ( int y = startY+1; y < endY; y++ )
			for ( int x = startX+1; x < endX; x++){
				Value E00=0,E01=0,E10=LARGE_WEIGHT,E11=0;

				if (seedX != x && seedY != y)
					e->add_term2(variables[(x-startX)+(y-startY)*blockWidth],
					         variables[(seedX-startX)+(seedY-startY)*blockWidth],E00,E01,E10,E11);

				int diff = abs(imRef(I,x,y)-color);
				int maxD = (int) variance*MULTIPLIER_VAR;
				if ( diff > maxD ) diff = maxD;

				int oldLabel = labeling[x+y*width];
				int oldY = Seeds[oldLabel]/width;
				int oldX = Seeds[oldLabel]-oldY*width;
				int oldColor = imRef(I,oldX,oldY);
				int oldDiff = abs(imRef(I,x,y)-oldColor);
				if ( oldDiff > maxD ) oldDiff = maxD;

				if ( oldDiff > diff) 
					 e->add_term1(variables[(x-startX)+(y-startY)*blockWidth],oldDiff-diff,0);
				else e->add_term1(variables[(x-startX)+(y-startY)*blockWidth],0,diff-oldDiff);
			}
	}


	// First set up horizontal links 
	for ( int y = startY; y <= endY; y++ )
		for ( int x = startX+1; x <=endX; x++){
			int oldLabelPix       = labeling[x+y*width];
			int oldLabelNeighbPix = labeling[x-1+y*width];
			Value E00,E01,E10,E11=0;

			if ( oldLabelPix != oldLabelNeighbPix ) 
				E00 = horizWeights[x-1+y*width];
			else E00 = 0;
			if ( oldLabelNeighbPix != label ) 
				E01 = horizWeights[x-1+y*width];
			else E01 = 0;
//.........这里部分代码省略.........
开发者ID:bwhite,项目名称:imseg,代码行数:101,代码来源:superpixels.cpp


注:本文中的Energy::add_term1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。