gcoptimization.h
来自「GraphCut Minimization Library 转换成 VC++6」· C头文件 代码 · 共 425 行 · 第 1/2 页
H
425 行
/* Peforms one iteration (one pass over all labels) of swap algorithm.*/
EnergyType oneSwapIteration();
/* Peforms swap on a pair of labels, specified by the input parameters alpha_label, beta_label */
EnergyType alpha_beta_swap(LabelType alpha_label, LabelType beta_label);
~GCoptimization();
/* Returns current label assigned to input pixel */
inline LabelType whatLabel(PixelType pixel){assert(pixel >= 0 && pixel < m_num_pixels);return(m_labeling[pixel]);};
/* Sets data cost of pixel to label */
inline void setDataCost(PixelType pixel, LabelType label, EnergyTermType cost){
assert(m_dataInput == SET_INDIVIDUALLY);
assert(pixel >= 0 && pixel < m_num_pixels && label >= 0 && label < m_num_labels );
m_datacost(pixel,label) = cost;};
/* Sets smooth cost for label1, label2 to cost. */
inline void setSmoothCost(LabelType label1, LabelType label2, EnergyTermType cost){
assert(m_smoothInput == SET_INDIVIDUALLY);
assert(label1 >= 0 && label1 < m_num_labels && label2 >= 0 && label2 < m_num_labels );
m_smoothcost(label1,label2) = cost;};
/* Makes pixel1 and pixel2 neighbors of each other. Can be called only 1 time for each */
/* unordered pair of pixels. Parameter weight can be used to set spacially varying terms */
/* If the desired penalty for neighboring pixels pixel1 and pixel2 is */
/* V(label1,label2) = weight*SmoothnessPenalty(label1,label2), then */
/* member function setLabel should be called as: setLabel(pixel1,pixel2,weight) */
void setNeighbors(PixelType pixel1, PixelType pixel2, EnergyTermType weight);
/* If the desired penalty for neighboring pixels pixel1 and pixel2 is */
/* V(label1,label2) = SmoothnessPenalty(label1,label2), then */
/* member function setLabel should be called as: setLabel(pixel1,pixel2) */
/* Also use this function to set up the neighborhood structure when energy terms are specified */
/* by a function pointer */
/* Again, this function can only be called one time for each distinct pair of pixels */
void setNeighbors(PixelType pixel1, PixelType pixel2);
/* This function can be used to change the label of any pixel at any time */
inline void setLabel(PixelType pixel, LabelType label){
assert(label >= 0 && label < m_num_labels && pixel >= 0 && pixel < m_num_pixels);m_labeling[pixel] = label;};
/* Returns Data Energy of current labeling */
EnergyType giveDataEnergy();
/* Returns Smooth Energy of current labeling */
EnergyType giveSmoothEnergy();
/* By default, the labels are visited in random order for both the swap and alpha-expansion moves */
/* Use this function with boolean argument 0 to fix the order to be not random */
/* Use this function with argumnet 1 to fix the order back to random */
void setLabelOrder(bool RANDOM_LABEL_ORDER);
/* This function is used to set the data term, and it can be used only if dataSetup = SET_ALL_AT_ONCE */
/* DataCost is an array s.t. the data cost for pixel p and label l is stored at */
/* DataCost[pixel*num_labels+l]. If the current neighborhood system is a grid, then */
/* the data term for label l and pixel with coordinates (x,y) is stored at */
/* DataCost[(x+y*width)*num_labels + l]. Thus the size of array DataCost is num_pixels*num_labels */
void setData(EnergyTermType *DataCost);
/* This function is used to set the data term, and it can be used only if dataSetup = SET_ALL_AT_ONCE */
/* dataFn is a pointer to a function f(Pixel p, Label l), s.t. the data cost for pixel p to have */
/* label l is given by f(p,l) */
void setData(dataFnPix dataFn);
/* This function is used to set the data term, and it can be used only if dataSetup = SET_ALL_AT_ONCE */
/* and only for the grid graph */
/* dataFn is a pointer to a function f(x, y, l), s.t. the data cost for pixel with coordinates (x,y) */
/* to have label l is given by f(x,y,l) */
void setData(dataFnCoord dataFn);
/* This function is used to set the smoothness term, and it can be used only if */
/* smoothSetup = SET_ALL_AT_ONCE */
/* V is an array of costs, such that V(label1,label2) is stored at V[label1+num_labels*label2] */
/* If graph is a grid, then using this function only if the smooth costs are not spacially varying */
/* that is the smoothness penalty V depends only on labels, but not on pixels */
void setSmoothness(EnergyTermType* V);
/* This function is used to set the smoothness term, and it can be used only if */
/* smoothSetup = SET_ALL_AT_ONCE AND the graph is a grid */
/* V is an array of costs, such that V(label1,label2) is stored at V[label1+num_labels*label2] */
/* hCue() is used to store the spacially varying coefficient w_pq. */
/* if p has coordinates (x,y) and q has coordinates (x+1,y) then w_pq = hCue[x+y*width] */
/* The smoothness penalty, therefore, is */
/* V_pq(label1,label2) = V[label1+num_labels*label2]*hCue[x+y*width] */
/* vCue() is used to store the spacially varying coefficient w_pq. */
/* if p has coordinates (x,y) and q has coordinates (x,y+1) then w_pq = vCue[x+y*width] */
/* The smoothness penalty, therefore, is */
/* V_pq(label1,label2) = V[label1+num_labels*label2]*vCue[x+y*width] */
void setSmoothness(EnergyTermType* V,EnergyTermType* hCue, EnergyTermType* vCue);
/* This function is used to set the smoothness term, and it can be used only if */
/* smoothSetup = SET_ALL_AT_ONCE */
/* cost is a function f(pix1,pix2,label1,label2) such that smoothness penalty for neigboring pixels */
/* pix1 and pix2 to have labels, respectively, label1 and label2 is f(pix1,pix2,label1,label2) */
void setSmoothness(smoothFnCoord cost);
/* This function is used to set the smoothness term, and it can be used only if */
/* smoothSetup = SET_ALL_AT_ONCE AND the graph is a grid */
/* horz_cost is a function f(x,y,label1,label2) such that smoothness penalty for neigboring pixels */
/* (x,y) and (x+1,y) to have labels, respectively, label1 and label2 is f(x,y,label1,label2) */
/* vert_cost is a function f(x,y,label1,label2) such that smoothness penalty for neigboring pixels */
/* (x,y) and (x,y+1) to have labels, respectively, label1 and label2 is f(x,y,label1,label2) */
void setSmoothness(smoothFnCoord horz_cost, smoothFnCoord vert_cost);
private:
typedef struct NeighborStruct{
PixelType to_node;
EnergyTermType weight;
} Neighbor;
typedef enum
{
ARRAY,
FUNCTION_PIX,
FUNCTION_COORD,
NONE,
} representationType;
int m_num_labels;
int m_width;
int m_height;
PixelType m_num_pixels;
LabelType *m_labeling;
representationType m_dataType;
representationType m_smoothType;
bool m_random_label_order;
bool m_grid_graph;
bool m_varying_weights; // this boolean flag is used only for grid graphs
int m_dataInput;
int m_smoothInput;
bool m_deleteLabeling;
EnergyTermType *m_datacost;
EnergyTermType *m_smoothcost;
EnergyTermType *m_vertWeights;
EnergyTermType *m_horizWeights;
LinkedBlockList *m_neighbors;
LabelType *m_labelTable;
PixelType *m_lookupPixVar;
EnergyTermType m_weight;
/* Pointers to function for energy terms */
dataFnPix m_dataFnPix;
dataFnCoord m_dataFnCoord;
smoothFnCoord m_horz_cost,m_vert_cost;
smoothFnPix m_smoothFnPix;
EnergyType start_expansion(int max_iterations);
EnergyType start_swap(int max_iterations);
EnergyType compute_energy();
void commonGridInitialization( PixelType width, PixelType height, int nLabels);
void commonNonGridInitialization(PixelType num_pixels, int num_labels);
void commonInitialization(int dataSetup, int smoothSetup);
void scramble_label_table();
void perform_alpha_expansion(LabelType label);
void perform_alpha_beta_swap(LabelType alpha_label, LabelType beta_label);
EnergyType giveDataEnergyArray();
EnergyType giveDataEnergyFnPix();
EnergyType giveDataEnergyFnCoord();
EnergyType giveSmoothEnergy_G_ARRAY_VW();
EnergyType giveSmoothEnergy_G_ARRAY();
EnergyType giveSmoothEnergy_G_FnPix();
EnergyType giveSmoothEnergy_G_FnCoord();
EnergyType giveSmoothEnergy_NG_ARRAY();
EnergyType giveSmoothEnergy_NG_FnPix();
void add_t_links_ARRAY(Energy *e,Energy::Var *variables,int size,LabelType alpha_label);
void add_t_links_FnPix(Energy *e,Energy::Var *variables,int size,LabelType alpha_label);
void add_t_links_FnCoord(Energy *e,Energy::Var *variables,int size,LabelType alpha_label);
void add_t_links_ARRAY_swap(Energy *e,Energy::Var *variables,int size,LabelType alpha_label,LabelType beta_label,PixelType *pixels);
void add_t_links_FnPix_swap(Energy *e,Energy::Var *variables,int size,LabelType alpha_label,LabelType beta_label,PixelType *pixels);
void add_t_links_FnCoord_swap(Energy *e,Energy::Var *variables,int size,LabelType alpha_label,LabelType beta_label,PixelType *pixels);
void set_up_expansion_energy_G_ARRAY_VW(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_expansion_energy_G_ARRAY(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_expansion_energy_G_FnPix(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_expansion_energy_G_FnCoord(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_expansion_energy_NG_ARRAY(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_expansion_energy_NG_FnPix(int size, LabelType alpha_label,Energy* e, Energy::Var *variables);
void set_up_swap_energy_G_ARRAY_VW(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void set_up_swap_energy_G_ARRAY(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void set_up_swap_energy_G_FnPix(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void set_up_swap_energy_G_FnCoord(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void set_up_swap_energy_NG_ARRAY(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void set_up_swap_energy_NG_FnPix(int size, LabelType alpha_label,LabelType beta_label,PixelType *pixels,Energy* e, Energy::Var *variables);
void initialize_memory();
void terminateOnError(bool error_condition,const char *message);
};
#endif // !defined(AFX_GCOPTIMIZATION_H__E7629E95_2265_42EA_934F_18AA93280A72__INCLUDED_)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?