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


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

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


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

示例1: expandOnLabel


//.........这里部分代码省略.........
	// 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;
			if ( label != oldLabelPix )
				E10 = horizWeights[x-1+y*width];
			else E10 = 0;
			
			e->add_term2(variables[(x-startX)-1+(y-startY)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
		}

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

			if ( oldLabelPix != oldLabelNeighbPix ) 
				E00 = vertWeights[x+(y-1)*width];
			else E00 = 0;
			if ( oldLabelNeighbPix != label ) 
				E01 = vertWeights[x+(y-1)*width];
			else E01 = 0;
			if ( label != oldLabelPix )
				E10 = vertWeights[x+(y-1)*width];
			else E10 = 0;

			
			e->add_term2(variables[(x-startX)+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
		}

	// Next set up diagonal links 
	float SQRT_2= 1/sqrt(2.0);
	for ( int y = startY+1; y <= endY; y++ )
		for ( int x = startX+1; x <=endX; x++){
			int oldLabelPix       = labeling[x+y*width];
			int oldLabelNeighbPix = labeling[x-1+(y-1)*width];
			Value E00,E01,E10,E11=0;
			
			if ( oldLabelPix != oldLabelNeighbPix ) 
				E00 = SQRT_2*diag1Weights[x-1+(y-1)*width];
			else E00 = 0;
			if ( oldLabelNeighbPix != label ) 
				E01 = SQRT_2*diag1Weights[x-1+(y-1)*width];
			else E01 = 0;
			if ( label != oldLabelPix )
				E10 = SQRT_2*diag1Weights[x-1+(y-1)*width];
			else E10 = 0;
			
			e->add_term2(variables[(x-startX)-1+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
		}
	
	// More diagonal links
	for ( int y = startY+1; y <= endY; y++ )
		for ( int x = startX; x <=endX-1; x++){
			int oldLabelPix       = labeling[x+y*width];
			int oldLabelNeighbPix = labeling[(x+1)+(y-1)*width];
			Value E00,E01,E10,E11=0;

			if ( oldLabelPix != oldLabelNeighbPix ) 
				E00 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
			else E00 = 0;
			if ( oldLabelNeighbPix != label ) 
				E01 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
			else E01 = 0;
			if ( label != oldLabelPix )
				E10 = SQRT_2*diag2Weights[(x+1)+(y-1)*width];
			else E10 = 0;

			e->add_term2(variables[(x-startX+1)+(y-startY-1)*blockWidth],variables[(x-startX)+(y-startY)*blockWidth],E00,E01,E10,E11);
		}


	e->minimize();

	for ( int y = startY; y <= endY; y++ )
		for ( int x = startX; x <= endX; x++){
			if ( e->get_var(variables[(x-startX)+(y-startY)*blockWidth]) != 0 )
			{
				if ( labeling[x+y*width] != label ){
					labeling[x+y*width] = label; 
					changeMaskNew[x+y*width] = 1;
					changeMask[x+y*width] = 1;
				}
			}
		}


	delete e;
}
开发者ID:bwhite,项目名称:imseg,代码行数:101,代码来源:superpixels.cpp


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