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
Interactive maxflow2d
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
- OpenCV's Graphcut implementation:https://github.com/opencv/opencv/blob/2.4/modules/imgproc/src/gcgraph.hpp
- SimpleCRF's maxflow implementation: https://github.com/HiLab-git/SimpleCRF
- Yuri Boykov and Vladimir Kolmogorov's maxflow implementation: https://pub.ist.ac.at/~vnk/software/maxflow-v3.04.src.zip
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file torchmaxflow-0.0.3rc1.tar.gz
.
File metadata
- Download URL: torchmaxflow-0.0.3rc1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b30139a661d9c690d67905d9a582c06a0e546b7e978822ee55868ec58148639 |
|
MD5 | f6cb5da1315bfdb3dbcc23cec0f26a59 |
|
BLAKE2b-256 | 78e9b77090062ed2515a47e4d395ca8948b3a92581cf738c694099a40776fb1a |