Skip to content

Segmentation: Implemention of a simple Chan-Vese Algorithm - #1957

Merged
sciunto merged 23 commits into
scikit-image:masterfrom
GGoussar:chanvese
Apr 13, 2017
Merged

sciunto merged 23 commits into
scikit-image:masterfrom
GGoussar:chanvese

Conversation

@GGoussar

Copy link
Copy Markdown
Contributor

I have implemented a simple Chan-Vese Algorithm in the segmentation module based mostly on matlab code by Yue Wu freely available at http://www.mathworks.com/matlabcentral/fileexchange/23445-chan-vese-active-contours-without-edges

Let me know what needs to be changed, improved or corrected and whether I have made any mistakes in the actual implementation of the algorithm.

This is part of a student project supervised by Olivier Debeir who is a contributor for this library. This is also my first time contributing to such a project, so please bear with me.
.

@@ -0,0 +1,25 @@
""" This is an example to illustrate the us of the Chan-Vese Algorithm.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, give a more detailed description including: main idea of the algorithm / difference from other segmentation algorithms already presented in skimage. Also, couple of reference links would be nice.

@soupault

Copy link
Copy Markdown
Member

@GGoussar thanks for the contribution, this looks really interesting!
I've added some comments mostly on the style improvement and gallery example fix. Code itself is quite nice and well-documented.
When you'll fix the metnioned points, I'd like to reloop again and see, where we can improve the code.
Thanks again and looking forward to see this in skimage!

@soupault

Copy link
Copy Markdown
Member

For sure, we'll need some tests for this feature. You may consider some toy cases and also add 1 test for any of the images we supply (https://github.com/scikit-image/scikit-image/tree/master/skimage/data).

@GGoussar

Copy link
Copy Markdown
Contributor Author

@soupault Thank you for your comments. I will do my best to correct the problems you have highlighted as soon as I can, hopefully within the next couple of days.

@emmanuelle

Copy link
Copy Markdown
Member

Welcome on board @GGoussar ! As @soupault says, there is still some work to do and we'll need some more iterations, but once it's finished, Chan-Vese segmentation will be a very nice contribution to scikit-image! Thanks!

@stefanv

stefanv commented Feb 23, 2016

Copy link
Copy Markdown
Member

@emmanuelle and I have been talking about getting Chan-Vese into the library since EuroSciPy 2011 or 12 :D I'm very happy to see it happen!

@GGoussar

Copy link
Copy Markdown
Contributor Author

Thank you for the input. Having reread the code I realise I might have to rewrite parts of it to reduce redundencies. I also have not corrected everything yet.

@GGoussar

GGoussar commented Mar 1, 2016

Copy link
Copy Markdown
Contributor Author

My apologies for the delay. I have been rather busy wih other things over the last week, and I have barely had any time to work on this code. I still need to reread the code and see what I can change to make it clearer. In the mean time, let me know how I could improve the comments for the example, which is what I did in this last commit.

@soupault

soupault commented Mar 2, 2016

Copy link
Copy Markdown
Member

@GGoussar regarding the gallery example:
As it was said before, you should use plt.subplots if you need to visualize 2 images. See, for example, http://scikit-image.org/docs/dev/auto_examples/filters/plot_nonlocal_means.html#example-filters-plot-nonlocal-means-py for reference. Two calls of plt.show() will not work as you might expect.
Also, please don't use print as it's output will never be shown anywhere. To notify on number of iterations you could use title (i.e., ax[1].set_title('Chan-Vese result, {} iterations'.format(str(len(cv[1]))))).

@GGoussar

GGoussar commented Mar 2, 2016

Copy link
Copy Markdown
Contributor Author

Right. Sorry, I somehow forgot about that.

@JDWarner

JDWarner commented Mar 2, 2016

Copy link
Copy Markdown
Contributor

If you want to get fancy, you can have text, code, and figures spaced out however you like! It's not used as often as it could be, but yields great results.

See for example the gallery example for Seam Carving to get the hang of this. You don't even have to call plt.show(), you just start the next block docstring text with a specific tag.

Comment thread skimage/segmentation/chanvese.py Outdated
.. [1] An Active Contour Model without Edges, Tony Chan and
Luminita Vese, Scale-Space Theories in Computer Vision, 1999
.. [2] Chan-Vese Segmentation, Pascal Getreuer Image Processing On
Line, 2 (2012), pp. 214�224.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-unicode –. Replace with -.

@soupault soupault left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to be merged. A great starting point for further enhancements and optimizations :).

@soupault

soupault commented Apr 13, 2017 •

Copy link
Copy Markdown
Member

Pinging contributors via @pep8speaks by pushing to their branches:
image

@pep8speaks

Copy link
Copy Markdown

Hello @GGoussar! Thanks for updating the PR.

Line 51:80: E501 line too long (80 > 79 characters)

Line 119:80: E501 line too long (81 > 79 characters)

@sciunto sciunto changed the title Implemention of a simple Chan-Vese Algorithm Segmentation: Implemention of a simple Chan-Vese Algorithm Apr 13, 2017
@sciunto
sciunto merged commit d020c22 into scikit-image:master Apr 13, 2017
@sciunto

sciunto commented Apr 13, 2017

Copy link
Copy Markdown
Member

Thank you for your patience and thanks for the different contributors. That's an awesome contribution.

@soupault

Copy link
Copy Markdown
Member

@GGoussar congratulations! Looking forward to seeing a faster multichannel version! 😉

@GGoussar

Copy link
Copy Markdown
Contributor Author

Thank you everyone for supporting me in doing this. I was (and still am) inexperienced with this, so you have my deepest gratitude for your patience.

nzoghb pushed a commit to nzoghb/scikit-image that referenced this pull request Apr 14, 2017
nzoghb pushed a commit to nzoghb/scikit-image that referenced this pull request Apr 14, 2017
@llanduyt

Copy link
Copy Markdown

Dear all,
I am new to Python and working with the Chan-Vese algorithm to segment images.
I would like to use the script but had a question regarding the updating of the phi function in _cv_calculate_variation. What is the purpose of the last line (new_phi / (1 + mu * dt * _cv_delta(phi) * (C1+C2+C3+C4)))?
Thanks!

@GGoussar

GGoussar commented Jun 19, 2017 •

Copy link
Copy Markdown
Contributor Author

If I remember correctly, it's an approximation of equation (22) in the article by Pascal Getreuer (http://www.ipol.im/pub/art/2012/g-cv/article.pdf, page 5/11). I did not look too much into it, but from what I understand, it stems from trying to separate phi at step n from phi at step n+1 in equation (21). My apologies, I'm not a mathematician, so please let me know if I've made a mistake.

By the way,it's only an approximation because unlike what is proposed in that article, this algorithm is not semi-implicit. I don't think there is a way to do it efficiently in python (although if that is the case, I would very much like to hear it).

@GGoussar
GGoussar deleted the chanvese branch June 19, 2017 11:18
@llanduyt

Copy link
Copy Markdown

That makes sense. Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.