📄 gcoptimization.h
字号:
// GCoptimization.h: interface for the GCoptimization class.
//
//////////////////////////////////////////////////////////////////////
/* GCoptimization.h */
/* Olga Veksler, 2005, olga@csd.uwo.ca */
/* Copyright 2005 Olga Veksler (olga@csd.uwo.ca)*/
/* email olga@csd.uwo.ca for any questions, suggestions and bug reports
/***************** IMPORTANT!!!!!!!!!!!***********************************************************
If you use this software, YOU HAVE TO REFERENCE (at least) 3 papers, the citations [1]
[2] and [3] below
/****************************************************************************************************/
/******************************************************************************/
/* For description and example usage see GC_README.TXT */
/******************************************************************************/
/*
This software library implements the Graph Cuts Energy Minimization methods
described in
[1] Efficient Approximate Energy Minimization via Graph Cuts
Yuri Boykov, Olga Veksler, Ramin Zabih,
IEEE transactions on PAMI, vol. 20, no. 12, p. 1222-1239, November 2001.
This software can be used only for research purposes, you should cite
the aforementioned paper in any resulting publication.
If you wish to use this software (or the algorithms described in the aforementioned paper)
for commercial purposes, you should be aware that there is a US patent:
R. Zabih, Y. Boykov, O. Veksler,
"System and method for fast approximate energy minimization via graph cuts ",
United Stated Patent 6,744,923, June 1, 2004
/* Together with the library implemented by O. Veksler, we provide, with the permission of the
V. Kolmogorov and Y. Boykov the following libraries:
1) energy.h, which was developed by Vladimir Kolmogorov and implements binary energy minimization
technique described in
[2] What Energy Functions can be Minimized via Graph Cuts?
Vladimir Kolmogorov and Ramin Zabih.
To appear in IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI).
Earlier version appeared in European Conference on Computer Vision (ECCV), May 2002.
We use "energy.h" to implement the binary energy minimization step
for the alpha-expansion and swap algorithms. The graph construction provided by "energy.h" is
more efficient (and slightly more general) than the original graph construction for the
alpha-expansion algorithm in the paper cited as [1]
This software can be used only for research purposes. IF YOU USE THIS SOFTWARE,
YOU SHOULD CITE THE AFOREMENTIONED PAPER [2] IN ANY RESULTING PUBLICATION.
2) graph.h, block.h, maxflow.cpp
This software library implements the maxflow algorithm
described in
[3] An Experimental Comparison of Min-Cut/Max-Flow Algorithms
for Energy Minimization in Vision.
Yuri Boykov and Vladimir Kolmogorov.
In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI),
September 2004
This algorithm was developed by Yuri Boykov and Vladimir Kolmogorov
at Siemens Corporate Research. To make it available for public use,
it was later reimplemented by Vladimir Kolmogorov based on open publications.
If you use this software for research purposes, you should cite
the aforementioned paper in any resulting publication.
*/
/* These 4 files (energy.h,graph.h, block.h, maxflow.cpp) are included in the curent library with permission of
Vladimir Kolmogorov and Yuri Boykov. They are included in a separate subdirectory named NotVekslerCode.
The can also be downloaded independently from Vladimir Kolmogorov's
website:http://research.microsoft.com/~vnk/
Please Note that Vladimir's website is likely to move in the future */
/****************************************************************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if !defined(AFX_GCOPTIMIZATION_H__E7629E95_2265_42EA_934F_18AA93280A72__INCLUDED_)
#define AFX_GCOPTIMIZATION_H__E7629E95_2265_42EA_934F_18AA93280A72__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "LinkedBlockList.h"
#include <assert.h>
#include "Graph.h"
#include "Energy.h"
#define m_datacost(pix,lab) (m_datacost[(pix)*m_num_labels+(lab)] )
#define m_smoothcost(lab1,lab2) (m_smoothcost[(lab1)+(lab2)*m_num_labels] )
#define SET_INDIVIDUALLY 0
#define SET_ALL_AT_ONCE 1
class GCoptimization
{
public:
///////////////////////////////////////////////////////////////////////////////////////
// First define needed data types //
///////////////////////////////////////////////////////////////////////////////////////
/* Type for the total energy calculation. Change it in Graph.h */
typedef Graph::flowtype EnergyType;
/* Type for the individual terms in the energy function.Change it in Graph.h */
typedef Graph::captype EnergyTermType;
/* Type of label. Can be set to char, short, int, long */
typedef int LabelType;
/* Type for pixel. Can be set to short, int, long */
typedef int PixelType;
/* The following 4 definitions are functions used to set data and smoothness terms */
typedef EnergyTermType (*smoothFnPix)(PixelType pix1, PixelType pix2, LabelType lab1, LabelType lab2);
typedef EnergyTermType (*smoothFnCoord)(PixelType x, PixelType y, LabelType l1, LabelType l2);
typedef EnergyTermType (*dataFnPix)(PixelType pix, LabelType lab);
typedef EnergyTermType (*dataFnCoord)(PixelType x, PixelType y, LabelType l);
///////////////////////////////////////////////////////////////////////////////////////
// Next define constructors //
///////////////////////////////////////////////////////////////////////////////////////
/* Use this constructor only for grid of size width by height. If you use this constructor, */
/* 4 connected grid neigbhorhood structure is assumed. num_labels is the number of labels, */
/* Labels are assumed to be in {0, 1, 2,....num_labels-1} */
/* dataSetup and smoothSetup can take only 2 values, namely SET_INDIVIDUALLY (0) and */
/* SET_ALL_AT_ONCE(1) */
/* In case dataSetup = SET_INDIVIDUALLY, to set the data cost you must use the */
/* member function setDataCost(pixel,label,cost). If dataSetup = SET_ALL_AT_ONCE, */
/* to set the data costs you must use any of the setData() functions. */
/* In case smoothSetup = SET_INDIVIDUALLY, to set the smooth cost you must use the */
/* member function setSmoothCost(label1,label2,cost). If smoothSetup = SET_ALL_AT_ONCE, */
/* to set the smoothness costs you must use any of the setSmoothness() functions. */
GCoptimization(PixelType width,PixelType height,int num_labels,int dataSetup, int smoothSetup);
/* This is the constructor for non-grid graphs. Everything is the same as in the constructor */
/* above, but neighborhood structure must be specified by any of the two setNeighbors() */
/* functions */
GCoptimization(PixelType num_pixels,int num_labels,int dataSetup, int smoothSetup);
/* This constructor is the same as the first constructor, but array m_answer for */
/* storage of the labels is passed. This will save space, as the answer will not have to be */
/* stored twice, once in the current class, and once in the class which calls this optimization */
/* class */
GCoptimization(LabelType *m_answer,PixelType num_pixels,int nLabels,int dataSetup, int smoothSetup);
/* This constructor is the same as the second constructor, but array m_answer for */
/* storage of the labels is passed. This will save space, as the answer will not have to be */
/* stored twice, once in the current class, and once in the class which calls this optimization */
/* class */
GCoptimization(LabelType *m_answer,PixelType width,PixelType height,int num_labels,int dataSetup, int smoothSetup);
/* Peforms expansion algorithm. Runs the number of iterations specified by max_num_iterations */
/* Returns the total energy of labeling */
EnergyType expansion(int max_num_iterations);
/* Peforms expansion algorithm. Runs it until convergence */
/* Returns the total energy of labeling */
EnergyType expansion();
/* Peforms one iteration (one pass over all labels) of expansion algorithm.*/
EnergyType oneExpansionIteration();
/* Peforms expansion on one label, specified by the input parameter alpha_label */
EnergyType alpha_expansion(LabelType alpha_label);
/* Peforms swap algorithm. Runs it the specified number of iterations */
EnergyType swap(int max_num_iterations);
/* Peforms swap algorithm. Runs it until convergence */
EnergyType swap();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -