Belief Propagation-Two Graphs
Download source: BP-TwoGraphs 1.01
Author: Kai Ju Liu | E-mail:
Setup
Unzip the file. BpTwoGraphs.h/.cc and CompatibilityFunctions.h are the core files. BpTwoGraphsSimpleTest.cc is a simple test file which demonstrates the material in the following two sections. If you're on a *nix platform, type "make test" to run it!
Compatibility Functions
Look inside CompatibilityFunctions.h. You'll see three abstract classes: PhiFunction, PsiSimpleFunction, and PsiFullFunction. To implement a compatibility function, simply derive a class from one of these abstract classes and define its eval function. For example, you might derive the LinearPhi class from the PhiFunction abstract class and define its eval function accordingly.
You'll need to derive one class from PhiFunction and one class from either PsiSimpleFunction or PsiFullFunction. You can now instantiate objects of each class and pass them to BpTwoGraphs.
BP-TwoGraphs
The BpTwoGraphs class constructor takes the dimensions of your lattice and the number of possible states. Once your BpTwoGraphs object is instantiated, you can run the BP-TwoGraphs algorithm using one of the run methods and your compatibility function objects defined above. For segmentation, you'll probably use a simple psi compatibility function, and for stereo, you'll probably use a full psi compatibility function.
How to retrieve your results? Use the getBestStates and getBestBeliefs methods. These return three-dimensional arrays - call them bestStates and bestBeliefs. You're interested in the third elements of these arrays, bestStates[2] and bestBeliefs[2], which are two-dimensional arrays. They contain, respectively, the most likely state at each lattice location and its associated belief.