资源简介

图像分割代码,作者V. Lempitsky, A. Blake, C. Rother. Image Segmentation by Branch-and-Mincut. In proceedings of European Conference on Computer Vision (ECCV), October 2008.

资源截图

代码片段和文件信息

/*
This software contains the C++ implementation of the “branch-and-mincut“ framework for image segmentation
with various high-level priors as described in the paper:

V. Lempitsky A. Blake C. Rother. Image Segmentation by Branch-and-Mincut. 
In proceedings of European Conference on Computer Vision (ECCV) October 2008.

The software contains the core algorithm and an example of its application (globally-optimal 
segmentations under Chan-Vese functional).

Implemented by Victor Lempitsky 2008
*/


#include “BranchAndMincut.h“
#include 
#include 
#include 

//using stl for the queue in the min
#include 
#include 
#include 
#include 


//////////////////////////////////


int imWidth = 0;
int imHeight = 0;
static int *bestSegm;
static Branch *bestBranch = NULL;
static gtype upperBound; //best leaf energy found so far

//////////////////////////////////////////////

static int statFlowCalls; //counting calls to lower bound/energy evaluations

//////////////////////////////////////////////


struct 
{
GraphT *graph;
gtype *bgUnaries;
gtype *fgUnaries;
bool maxflowWasCalled;

void Reset(gtype *pairwise gtype *commonUnaries)
{
maxflowWasCalled = false;
graph->reset();
graph->add_node(imWidth*imHeight);

int xyi;

if(commonUnaries)
for(i = 0; i < imWidth*imHeight; i++)
{
if(commonUnaries[i] > 0)
graph->add_tweights(i commonUnaries[i] 0);
else
graph->add_tweights(i 0 -commonUnaries[i]);
}


for(y = 0 i = 0; y < imHeight; y++)
for(x = 0; x < imWidth; x++ i++)
{
if(y && x < imWidth-1) graph->add_edge(i i-imWidth+1 pairwise[i*4] pairwise[i*4]);
if(x < imWidth-1) graph->add_edge(i i+1 pairwise[i*4+1] pairwise[i*4+1]);
if(y < imHeight-1 && x < imWidth-1) graph->add_edge(i i+imWidth+1 pairwise[i*4+2] pairwise[i*4+2]);
if(y < imHeight-1) graph->add_edge(i i+imWidth pairwise[i*4+3] pairwise[i*4+3]);
}

memset(fgUnaries 0 sizeof(gtype)*imWidth*imHeight);
memset(bgUnaries 0 sizeof(gtype)*imWidth*imHeight);
}
} reusable;

void PrepareGraph(int imwidth int imheight)
{
imWidth = imwidth;
imHeight = imheight;

reusable.graph = new GraphT(imwidth*imheight imwidth*imheight*4);
reusable.bgUnaries = new gtype[imwidth*imheight];
reusable.fgUnaries = new gtype[imwidth*imheight];
}

void ReleaseGraph()
{
delete reusable.graph;
delete reusable.bgUnaries;
delete reusable.fgUnaries;
}
//////////////////////////////////////////

//STL stuff

struct BranchWrapper
{
Branch *br;
BranchWrapper(Branch *b): br(b) {}
};

using namespace std;
bool operator<(const BranchWrapper& a const BranchWrapper& b)
{
return a.br->bound < b.br->bound;
}
bool operator>(const BranchWrapper& a const BranchWrapper& b)
{
return a.br->bound > b.br->bound;
}
typedef std::priority_queue

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        7332  2008-09-22 13:49  BranchAndMincut.cpp
     文件        2961  2008-09-22 13:49  BranchAndMincut.h
     文件        4027  2008-09-22 14:27  ChanVeseSegmentation.cpp
     文件        1931  2008-09-22 13:49  ChanVeseSegmentation.h
     文件       59983  2008-09-22 14:23  lake.png
     文件        3703  2008-09-22 13:52  ReadMe.txt
     文件        6111  2008-11-13 17:02  license.txt
     文件        3023  2009-10-14 16:03  image.h
     文件        5385  2009-10-14 15:52  BranchAndMincut.vcproj
     文件         894  2009-10-14 15:52  BranchAndMincut.sln
     文件        7466  2006-11-07 18:56  Maxflow\block.h
     文件        1166  2006-11-07 21:01  Maxflow\CHANGES.TXT
     文件        3029  2006-11-16 20:16  Maxflow\graph.cpp
     文件       17739  2009-10-14 14:27  Maxflow\graph.h
     文件         410  2006-06-13 18:42  Maxflow\instances.inc
     文件       15569  2006-11-16 20:16  Maxflow\maxflow.cpp
     文件        4430  2009-10-14 14:12  Maxflow\README.TXT

评论

共有 条评论