Skip to main content

No project description provided

Project description

torchmaxflow: Max-flow/Min-cut in PyTorch for 2D images and 3D volumes

Pytorch-based implementation of Max-flow/Min-cut based on the following paper:

  • Boykov, Yuri, and Vladimir Kolmogorov. "An experimental comparison of min-cut/max-flow algorithms for energy minimization in vision." IEEE transactions on pattern analysis and machine intelligence 26.9 (2004): 1124-1137.

This repository depends on the code for maxflow from OpenCV v2.4: https://github.com/opencv/opencv/blob/2.4/modules/imgproc/src/gcgraph.hpp, which has been included. It has same license, i.e. BSD-3 Clause, as torchmaxflow.

Citation

If you use this code in your research, then please consider citing:

Asad, Muhammad, Lucas Fidon, and Tom Vercauteren. "ECONet: Efficient Convolutional Online Likelihood Network for Scribble-based Interactive Segmentation." Medical Imaging with Deep Learning (MIDL), 2022.

Installation instructions

pip install torchmaxflow

or

# Clone and install from github repo

$ git clone https://github.com/masadcv/torchmaxflow
$ cd torchmaxflow
$ pip install -r requirements.txt
$ python setup.py install

Example outputs

Maxflow2d

./figures/torchmaxflow_maxflow2d.png

Interactive maxflow2d

./figures/torchmaxflow_intmaxflow2d.png

figures/figure_torchmaxflow.png

Example usage

The following demonstrates a simple example showing torchmaxflow usage:

image = np.asarray(Image.open('data/image2d.png').convert('L'), np.float32)
image = torch.from_numpy(image).unsqueeze(0).unsqueeze(0)

prob = np.asarray(Image.open('data/image2d_prob.png'), np.float32)
prob = torch.from_numpy(prob).unsqueeze(0)

lamda = 20.0
sigma = 10.0

post_proc_label = torchmaxflow.maxflow(image, prob, lamda, sigma)

For more usage examples see:

2D and 3D maxflow and interactive maxflow examples: demo_maxflow.py

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

torchmaxflow-0.0.3rc2-cp39-cp39-win_amd64.whl (84.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

torchmaxflow-0.0.3rc2-cp39-cp39-macosx_10_15_x86_64.whl (71.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

torchmaxflow-0.0.3rc2-cp38-cp38-win_amd64.whl (84.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

torchmaxflow-0.0.3rc2-cp38-cp38-macosx_10_14_x86_64.whl (71.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

torchmaxflow-0.0.3rc2-cp37-cp37m-win_amd64.whl (84.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

torchmaxflow-0.0.3rc2-cp37-cp37m-macosx_10_14_x86_64.whl (71.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

torchmaxflow-0.0.3rc2-cp36-cp36m-win_amd64.whl (84.8 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

torchmaxflow-0.0.3rc2-cp36-cp36m-macosx_10_14_x86_64.whl (71.0 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page