Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grabcut Implementation #1601

Open
charliebudd opened this issue Feb 19, 2021 · 6 comments
Open

Grabcut Implementation #1601

charliebudd opened this issue Feb 19, 2021 · 6 comments
Assignees

Comments

@charliebudd
Copy link
Collaborator

Grabcut (presented here) is a method of segmenting a reigion based on a sparse initial labeling.

A color model is employed (GMM is common) to determine color distibutions of the labeled reigions. These distributions are then used to asign proberbilities to unlabled regions of the image. Graphcut is then employed to optimize the boundries of the reigions based on the morphological boundries of the original image. This process may be iterated on until convergence.

This will be useful in MONAI for both interactive segmentation and as a post-processing step for segmentation algorithms.

I see this being split into three PRs. GMM, Graphcut, and finally Grabcut. Each would provide useful functionality induvidually.

@tvercaut
Copy link
Member

For the record, a good starting point in terms of implementation is the one from @luiscarlosgph
https://github.com/luiscarlosgph/grabcut
Itself mostly borrowing from that in OpenCV + code from old CUDA samples

@tvercaut
Copy link
Member

A few more components are now available, with some starting to be used in MONAILabel.

@masadcv implemented a wrapper for OpenCV's graphcut algorithm here:
https://github.com/masadcv/numpymaxflow
There is also a wrapper for pytorch directly but it faces some issues related to packaging (https://github.com/masadcv/torchmaxflow). Ideally, this would be integrated in MONAI proper and the packaging issue addressed in MONAI.

It also seems that the JIT-based compilation used for the GMM code here may not solve all packaging issues, see:
Project-MONAI/MONAILabel#763 (comment)
Until this is solved, would it be possible to have a pure-python fallback for the GMM? An implementation for it can for example be borrowed from https://github.com/ldeecke/gmm-torch

@masadcv
Copy link
Contributor

masadcv commented May 4, 2022

I may be able to help integrate torchmaxflow into MONAI (if this is something of interest here).
As @tvercaut pointed out, this may first need packaging to be addressed such that C++ based torch implementations can be packaged and deployed within MONAI.

We have already seen significance of using maxflow algorithm in MONAI Label (Project-MONAI/MONAILabel#731) and I am sure it will be useful for other segmentation processing applications as well.

@tvercaut
Copy link
Member

tvercaut commented May 4, 2022

The packaging question and c++ implementation of graphcut can be dealt with independently I think. We can already get a JIT-based approach in MONAI and once a more robust packaging approach is ready, it can be applied to all c++ extensions already available. The packaging will anyway require cleanup as there are already 2 different approaches to includin c++ extensions in MONAI:
https://github.com/Project-MONAI/MONAI/tree/dev/monai/_extensions
https://github.com/Project-MONAI/MONAI/tree/dev/monai/csrc

@masadcv
Copy link
Contributor

masadcv commented May 4, 2022

Agreed, this can be addressed independently from packaging. I can add a JIT module for this.

In terms of packaging, it is certainly needed in order to use such MONAI functions as dependency in other projects—we have already seen a number of issues with dependencies that required compilation (e.g. SImpleCRF dependency issues in MONAI Label see for example: Project-MONAI/MONAILabel#605 and Project-MONAI/MONAILabel#719) and hence it would be good to address this for MONAI C++ functions.

@tvercaut
Copy link
Member

tvercaut commented May 5, 2022

@masadcv: Unless there is an existing MONAI-related issue on packaging, can you create one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants