资源简介
Boykov的经典的Labeling算法,用于GraphCut。
To use this software, YOU MUST CITE the following in any resulting publication:
[1] Efficient Approximate Energy Minimization via Graph Cuts.
Y. Boykov, O. Veksler, R.Zabih. IEEE TPAMI, 20(12):1222-1239, Nov 2001.
[2] What Energy Functions can be Minimized via Graph Cuts?
V. Kolmogorov, R.Zabih. IEEE TPAMI, 26(2):147-159, Feb 2004.
[3] An Experimental Comparison of Min-Cut/Max-Flow Algorithms for
Energy Minimization in Vision. Y. Boykov, V. Kolmogorov.
IEEE TPAMI, 26(9):1124-1137, Sep 2004.
Furthermore, if you use the label cost feature (setLabelCost), you should cite
[4] Fast Approximate Energy Minimization with Label Costs.
A. Delong, A. Osokin, H. N. Isack, Y. Boykov. In CVPR, June 2010.
代码片段和文件信息
//////////////////////////////////////////////////////////////////////////////
// Example illustrating the use of GCoptimization.cpp
//
/////////////////////////////////////////////////////////////////////////////
//
// Optimization problem:
// is a set of sites (pixels) of width 10 and hight 5. Thus number of pixels is 50
// grid neighborhood: each pixel has its left right up and bottom pixels as neighbors
// 7 labels
// Data costs: D(pixellabel) = 0 if pixel < 25 and label = 0
// : D(pixellabel) = 10 if pixel < 25 and label is not 0
// : D(pixellabel) = 0 if pixel >= 25 and label = 5
// : D(pixellabel) = 10 if pixel >= 25 and label is not 5
// Smoothness costs: V(p1p2l1l2) = min( (l1-l2)*(l1-l2) 4 )
// Below in the main program we illustrate different ways of setting data and smoothness costs
// that our interface allow and solve this optimizaiton problem
// For most of the examples we use no spatially varying pixel dependent terms.
// For some examples to demonstrate spatially varying terms we use
// V(p1p2l1l2) = w_{p1p2}*[min((l1-l2)*(l1-l2)4)] with
// w_{p1p2} = p1+p2 if |p1-p2| == 1 and w_{p1p2} = p1*p2 if |p1-p2| is not 1
#include
#include
#include
#include
#include
#include “GCoptimization.h“
struct ForDataFn{
int numLab;
int *data;
};
int smoothFn(int p1 int p2 int l1 int l2)
{
if ( (l1-l2)*(l1-l2) <= 4 ) return((l1-l2)*(l1-l2));
else return(4);
}
int dataFn(int p int l void *data)
{
ForDataFn *myData = (ForDataFn *) data;
int numLab = myData->numLab;
return( myData->data[p*numLab+l] );
}
////////////////////////////////////////////////////////////////////////////////
// smoothness and data costs are set up one by one individually
// grid neighborhood structure is assumed
//
void GridGraph_Individually(int widthint heightint num_pixelsint num_labels)
{
int *result = new int[num_pixels]; // stores result of optimization
try{
GCoptimizationGridGraph *gc = new GCoptimizationGridGraph(widthheightnum_labels);
// first set up data costs individually
for ( int i = 0; i < num_pixels; i++ )
for (int l = 0; l < num_labels; l++ )
if (i < 25 ){
if( l == 0 ) gc->setDataCost(il0);
else gc->setDataCost(il10);
}
else {
if( l == 5 ) gc->setDataCost(il0);
else gc->setDataCost(il10);
}
// next set up smoothness costs individually
for ( int l1 = 0; l1 < num_labels; l1++ )
for (int l2 = 0; l2 < num_labels; l2++ ){
int cost = (l1-l2)*(l1-l2) <= 4 ? (l1-l2)*(l1-l2):4;
gc->setSmoothCost(l1l2cost);
}
printf(“\nBefore optimization energy is %d“gc->compute_energy());
gc->expansion(2);// run expansion for 2 iterations. For swap use gc->swap(num_iterations);
printf(“\nAfter optimization energy is %d“gc->compute_energy());
for ( int i = 0; i < num_pixels; i++ )
result[i] = gc->whatLabel(i);
delete gc;
}
catch (GCExcep
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-04-13 15:37 Labeling\
文件 7466 2006-11-07 06:56 Labeling\block.h
文件 10348 2010-08-31 10:45 Labeling\energy.h
文件 13232 2010-04-28 19:59 Labeling\example.cpp
文件 61540 2011-04-12 12:55 Labeling\GCoptimization.cpp
文件 27069 2010-07-22 10:58 Labeling\GCoptimization.h
文件 21133 2010-04-28 21:22 Labeling\GCO_README.TXT
文件 3005 2010-04-26 22:28 Labeling\graph.cpp
文件 17790 2010-04-25 13:24 Labeling\graph.h
文件 1453 2005-08-25 12:01 Labeling\li
文件 1765 2005-07-21 10:02 Labeling\li
目录 0 2012-04-13 15:37 Labeling\matlab\
文件 2553 2010-11-25 17:18 Labeling\matlab\GCO_BuildLib.m
文件 387 2009-10-27 15:45 Labeling\matlab\GCO_ComputeEnergy.m
文件 526 2010-04-26 22:20 Labeling\matlab\GCO_Create.m
文件 223 2010-04-13 21:38 Labeling\matlab\GCO_Delete.m
文件 303 2009-10-27 15:45 Labeling\matlab\GCO_ExpandOnAlpha.m
文件 1091 2010-04-28 11:30 Labeling\matlab\GCO_Expansion.m
文件 670 2009-10-27 15:47 Labeling\matlab\GCO_GetLabeling.m
文件 370 2010-04-13 21:37 Labeling\matlab\GCO_ListHandles.m
文件 507 2010-07-05 22:38 Labeling\matlab\GCO_LoadLib.m
文件 18497 2010-09-11 18:28 Labeling\matlab\gco_matlab.cpp
文件 2068 2010-07-05 22:39 Labeling\matlab\GCO_SetDataCost.m
文件 1695 2010-04-23 10:50 Labeling\matlab\GCO_SetLabelCost.m
文件 787 2010-04-23 10:52 Labeling\matlab\GCO_SetLabeling.m
文件 607 2010-04-22 14:36 Labeling\matlab\GCO_SetLabelOrder.m
文件 1198 2010-04-20 19:58 Labeling\matlab\GCO_SetNeighbors.m
文件 1380 2010-04-23 10:53 Labeling\matlab\GCO_SetSmoothCost.m
文件 1155 2010-04-26 22:16 Labeling\matlab\GCO_SetVerbosity.m
文件 702 2010-04-19 20:49 Labeling\matlab\GCO_Swap.m
文件 16858 2010-07-08 09:59 Labeling\matlab\GCO_UnitTest.m
............此处省略2个文件信息
评论
共有 条评论