Zoltan Kato
  [    Research Group   |   Software   |   Publications   |   Teaching   |   Contact info   |   CV   |   Photography   ]

Supervised Image Segmentation Using Markov Random Fields

Please acknowledge the use of our programs by referring to the relevant publications.

This is the sample implementation of a Markov random field based image segmentation algorithm described in the following papers:

  1. Mark Berthod, Zoltan Kato, Shan Yu, and Josiane Zerubia. Bayesian Image Classification Using Markov Random Fields. Image and Vision Computing, 14:285--295, 1996. Keyword(s): Bayesian image classification, Markov random fields, Optimisation.

  2. Zoltan Kato, Josiane Zerubia, and Mark Berthod. Satellite Image Classification Using a Modified Metropolis Dynamics. In Proceedings of International Conference on Acoustics, Speech and Signal Processing, volume 3, San-Francisco, California, USA, pages 573-576, March 1992. IEEE.

  3. Zoltan Kato. Modélisations markoviennes multirésolutions en vision par ordinateur. Application a` la segmentation d'images SPOT. PhD Thesis, INRIA, Sophia Antipolis, France, December 1994. Note: Available in French (follow the URL link) and English. Keyword(s): computer vision, early vision, Markovian model, multiscale model, hierarchical model, parallel combinatorial optimization algorithm, multi-temperature annealing, parameter estimation.

The main code (mrf.cpp) has been written by Csaba Gradwohl with some minor contributions from Zoltan Kato. The code is released under the GNU General Public License.

The program uses the Mersenne Twister random number generator written by Agner Fog. The generator itself is described in the following paper:

  • M. Matsumoto and T. Nishimura. Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator. ACM Transactions on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 (1998).


The code is platform independent. We have succesfully compiled it under Linux (RedHat, Fedora, Debian) and Windows (XP, 2003 server).

  • You need wxWidgets 2.8 or later.
  • Under Linux/Unix, please edit the makefile under the linux subdirectory and then

    $ make clean

    $ make

    should compile and install the program (it is called mrfdemo).
  • Under Windows, we provide .NET 2005 (VC++8) compatible project files. Open the mrfdemo solution file under the windows subdirectory and choose Build -> Rebuild mrfdemo from the menu to compile the program (it is called mrfdemo.exe). Make sure the environment variable WXWIN is set correctly, otherwise you have to modify the project settings. Note that only the Release configuration works properly.
  • Alternatively, you can also use the older wxWindows 2.4 compatible solution files found under the subdirectory windows-wxwin-2.4.x. We provide both VC++6 as well as .NET (VC++7) compatible project files. Of course, you need a properly installed wxWindows 2.4 in order to succesfully compile these versions.

Usage Notes

The program works on BMP images. Some test images are provided under the images subdirectory. The program GUI should be intuitive. Main steps:

  1. Load an image.
  2. Enter the number of pixel classes (~region type).
  3. Push Select classes button.
  4. Press left mouse button over the input image and draw a rectangle over a representative region of the first class. Then push Next class button. The mean and variance should appear in the Class parameters window. Continue with the next class until a representative rectangle for all classes has been selected.
  5. Set the weight of doubleton potentials (default is 0.9) and the stopping threshold (iterations are stopped when the energy change is less than the specified value).
  6. Choose the optimization method from the pull-down list.
  7. Adjust the optimization method's parameters: T0 - Initial temperature; c - temperature scheduler (T(n+1) = c*T(n)); alpha - MMD's probability threshold.
  8. Push Do it >> button to execute segmentation.
  9. Optionally, you can save the segmentation result as a BMP image.

During segmentation, the current classification along with the temperature and global energy are displayed at each iteration. At the end, the elapsed CPU time (excluding GUI overhead!) is also displayed.


Full source and precompiled binaries are available as a gziped tar or zip archive.

The older wxWindows 2.4 compatible sources are also available as a gziped tar or zip archive.

  [    Research Group   |   Software   |   Publications   |   Teaching   |   Contact info   |   CV   |   Photography   ]
Last modified: Mon Jan 12 17:06:32 CET 2009