Home

Awesome

pyGCO: a python wrapper for the graph cuts

The original wrapper is pygco

PyPI - Python Version PyPI Status PyPI Status

CI testing codecov Codacy Badge pre-commit.ci status

<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/9c11485e2f4f23189069/maintainability)](https://codeclimate.com/github/Borda/pyGCO/maintainability) [![Coverage Badge](https://api.shippable.com/projects/5883a5e12a5d900f00b8b9ff/coverageBadge?branch=master)](https://app.shippable.com/github/Borda/pyGCO) -->

This is a python wrapper for gco-v3.0 package, which implements a graph cuts based move-making algorithm for optimization in Markov Random Fields.

It contains a copy of the gco-v3.0 package. Some of the design were borrowed from the gco_python package. However, compared to gco_python:

This wrapper is composed of two parts, a C wrapper and a python wrapper.

Implemented functions

Building wrapper

  1. download the last version of gco-v3.0 to the gco_source
  2. compile gco-v3.0 and the C wrapper using make
  3. compile test_wrapper using make test_wrapper
  4. run the C test code ./test_wrapper (now you have the C wrapper ready)
make download
make all
make test_wrapper
./test_wrapper

The successful run should return:

labels = [ 0 2 2 1 ], energy=19
data energy=15, smooth energy=4

Next test the python wrapper using python test_examples.py, if it works fine you are ready to use pygco.

To include pygco in your code, simply import pygco module. See the documentation inside code for more details.

Install wrapper

Clone repository and enter folder, then

pip install -r requirements.txt
python setup.py install

Now it can be also installed from PyPi

pip install gco-wrapper

Show test results

Visualisation of the unary terns for binary segmentation

unary terms

4-connected components with the initial labeling (left) and estimated labeling with regularisation 1 (middle) and 0 (right)

labelling

8-connected components with the initial labeling (left) and estimated labeling with regularisation 1 (middle) and 0 (right)

labelling

Visualisation of the unary terns for 3 labels segmentation

unary terms

with the initial labeling (left) and estimated labeling (right)

labelling