Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnPixelSegCRFInference.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnPixelSegCRFInference.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <cstdlib>
16 #include <cassert>
17 #include <iostream>
18 #include <fstream>
19 #include <iomanip>
20 #include <vector>
21 
22 #include "Eigen/Core"
23 
24 #include "cv.h"
25 
26 #include "drwnBase.h"
27 #include "drwnPGM.h"
28 #include "drwnVision.h"
29 
30 using namespace std;
31 
32 // drwnPixelSegCRFInference class -----------------------------------------
40 
42  public:
44  drwnPixelSegCRFInference() { /* do nothing */ };
46  virtual ~drwnPixelSegCRFInference() { /* do nothing */ };
47 
52  void alphaExpansion(drwnSegImageInstance *instance, double contrastStrength = 0.0,
53  double higherOrderStrength = 0.0, double longRangeStrength = 0.0) const;
54 
56  double energy(const drwnSegImageInstance *instance, double contrastStrength = 0.0,
57  double higherOrderStrength = 0.0, double longRangeStrength = 0.0) const;
58 
59  protected:
62  virtual void addAuxiliaryVariables(drwnMaxFlow *g, const drwnSegImageInstance *instance) const;
63 
66  double addUnaryTerms(drwnMaxFlow *g, const drwnSegImageInstance *instance,
67  int alpha, int varOffset = 0) const;
68 
71  double addPairwiseContrastTerms(drwnMaxFlow *g, double contrastStrength,
72  const drwnSegImageInstance *instance, int alpha, int varOffset = 0) const;
73 
76  double addLongRangePairwiseTerms(drwnMaxFlow *g, double longRangeStrength,
77  const drwnSegImageInstance *instance, int alpha, int varOffset = 0) const;
78 
81  virtual double addHigherOrderTerms(drwnMaxFlow *g, double higherOrderStrength,
82  const drwnSegImageInstance* instance, int alpha, int varOffset = 0) const;
83 
85  double computeUnaryEnergy(const drwnSegImageInstance *instance) const;
86 
88  double computePairwiseContrastEnergy(const drwnSegImageInstance *instance, double contrastStrength) const;
89 
91  double computeLongRangePairwiseEnergy(const drwnSegImageInstance *instance, double longRangeStrength) const;
92 
94  virtual double computeHigherOrderEnergy(const drwnSegImageInstance *instance,
95  double higherOrderStrength) const;
96 };
97 
98 // drwnRobustPottsCRFInference -----------------------------------------------
106 
108  public:
109  double _eta;
111 
112  public:
113  drwnRobustPottsCRFInference(double eta = 0.25, bool bWeightBySize = true) :
114  _eta(eta), _bWeightBySize(bWeightBySize) { /* do nothing */ };
115  ~drwnRobustPottsCRFInference() { /* do nothing */ };
116 
117  protected:
118  void addAuxiliaryVariables(drwnMaxFlow *g, const drwnSegImageInstance* instance) const;
119 
120  double addHigherOrderTerms(drwnMaxFlow *g, double higherOrderStrength,
121  const drwnSegImageInstance* instance, int alpha, int varOffset = 0) const;
122 
123  double computeHigherOrderEnergy(const drwnSegImageInstance *instance,
124  double higherOrderStrength) const;
125 };
126 
127 // drwnWeightedRobustPottsCRFInference ---------------------------------------
136 
138  public:
139  double _eta;
140 
141  public:
142  drwnWeightedRobustPottsCRFInference(double eta = 0.25) : _eta(eta) { /* do nothing */ };
143  ~drwnWeightedRobustPottsCRFInference() { /* do nothing */ };
144 
145  protected:
146  void addAuxiliaryVariables(drwnMaxFlow *g, const drwnSegImageInstance* instance) const;
147 
148  double addHigherOrderTerms(drwnMaxFlow *g, double higherOrderStrength,
149  const drwnSegImageInstance* instance, int alpha, int varOffset = 0) const;
150 
151  double computeHigherOrderEnergy(const drwnSegImageInstance *instance,
152  double higherOrderStrength) const;
153 };
Encapsulates a single instance of an image for multi-class pixel labeling problems (i...
Definition: drwnSegImageInstance.h:47
drwnPixelSegCRFInference()
default constructor
Definition: drwnPixelSegCRFInference.h:44
and where 0.0 < < 0.5, W_c = w_i
Definition: drwnPixelSegCRFInference.h:137
Alpha-expansion inference for a pixel-level CRF model with unary, contrast-dependent pairwise...
Definition: drwnPixelSegCRFInference.h:41
virtual ~drwnPixelSegCRFInference()
destructor
Definition: drwnPixelSegCRFInference.h:46
double _eta
robustness parameter
Definition: drwnPixelSegCRFInference.h:139
and where 0.0 < < 0.5
Definition: drwnPixelSegCRFInference.h:107
bool _bWeightBySize
weight potential by superpixel/clique size
Definition: drwnPixelSegCRFInference.h:110
Interface for maxflow/min-cut algorithms (for minimizing submodular quadratic pseudo-Boolean function...
Definition: drwnMaxFlow.h:32
double _eta
robustness parameter
Definition: drwnPixelSegCRFInference.h:109