File Exchange

image thumbnail

Snake : Active Contour

version 1.7 (40.9 KB) by

Snake Segmentation (Kass et al), 2D/3D including GVF and balloon force (Easy to read code)

4.27273
27 Ratings

304 Downloads

Updated

View License

These functions implements the basic snake segmentation contour, as introduced by Kass et al.

Algorithm:
A snake is an active (moving) contour, in which the points are attracted by edges and other image boundaries. To keep the contour smooth, a membrane and thin plate energy is used as contour regularization.

Implementation:
All code is well commented, and is probably easy readable. It includes,
- A balloon force, which is not in the original paper
- Binary image segmentation result,
- The "Gradient Vector Flow" (GVF) method.
- 3D implementation, including parameter to keep the mesh from self-intersecting

Try the example in the help of function Snake.m !

Literature:
- Michael Kass, Andrew Witkin and Demetri TerzoPoulos "Snakes Active Contour Models", 1987
- Jim Invins and John Porril, "Everything you always wanted to know about snakes (but were afraid to ask)
- Chenyang Xu and Jerry L. Prince, "Gradient Vector Flow: A New external force for Snakes
- Christoph Lurig, Leif Kobbelt, Thomas Ertl, "Hierachical solutions for the Deformable Surface Problem in Visualization"

Please report bugs, successes and other comments

Comments and Ratings (52)

dinial utami

Chris Volpe

Hi Dirk-Jan,

Thanks for sharing this. I'm trying to get a better understanding of this so that I can modify it to suit a specific application. While examining SnakeMoveIteration2D.m, I see the following:

ssx = gamma*P(:,1) + Fext1(:,1) + Fext2(:,1);
ssy = gamma*P(:,2) + Fext1(:,2) + Fext2(:,2);

Gamma is the time step. I can't understand why you would multiply the POINTS THEMSELVES by the time step. A Gamma of anything other than unity would seem to produce non-sensible results. I would have expected something more along the lines of:

ssx = P(:,1) + gamma*(Fext1(:,1) + Fext2(:,1));
ssy = P(:,2) + gamma*(Fext1(:,2) + Fext2(:,2));

The reason I'm looking into this is that I'm trying to provide an additional energy function that exhibits a preference for straight lines and right-angle bends in the resulting snake.

chong yang

Marlon

Marlon (view profile)

shivangi b

please tell is getsnake command in MATLAB2010Ra ?
getsnake command is not avaliable in MATLAB2015Ra.please tell is any other command for getsnake in MATLAB2015Ra ?? my id is shivangisbv@gmail.com

Marlon

Marlon (view profile)

i need to segment the specific area of pixel in an image.i prefer the seeded region growing method please explain the idea about the code srg

li li

li li (view profile)

this is very useful for me .thank you.

Zizhao Zhang

keerthi v

after the energy optimized output red line area how can i extract my selected image automatically

Dirk-Jan,

If I want to determine register (rather than segment) can I simply take the Eext values from ExternalForceImage2D and insert them into the bspline_transform (from your b-splines program)?

Thanks

I tried the code (22 lines, as it is, without editing) mentioned under "Example, Basic:" in "Snake2D.m". This is the error I am getting:

To use 'interp', you might need:
  interp - Control System Toolbox
  interp - Signal Processing Toolbox
  interp - System Identification Toolbox

Error in InterpolateContourPoints2D (line 32)
O(:,1)=interp([P(end-3:end,1);P(:,1);P(:,1);P(1:4,1)],10);

Error in Snake2D (line 127)
P=InterpolateContourPoints2D(P,Options.nPoints);

Your File Information says only Image Processing Toolbox is required to use your submitted code.

Is there anything I am doing wrong? I just want to detect contour of an example image I have in:
http://stackoverflow.com/questions/27418314/extract-co-ordinates-from-detected-contour

Any comments will be appreciated.

Regards.

Hi,

I am trying to use the snake2D file on the testimage provided. However, my MATLAB is crashing when I use the test code.
Can anyone provide a reason as to why this is happening and any poosible solutions.
Thanks!

Jr-Shin Chen

"Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)" is because you are calling the function in the snake2D.m or snake3D.m itself. It will cause endless loop.
So, try to copy the example codes and paste to Matlab command window. Then you'll get the results!!

Christian

In SnakeMoveIteration3D.m I had to change the last line
FV.vertices=V;
to
FV.vertices=real(V);
to avoid an errror.

I'm using isosurface to to mesh a hemisphere and then reduce the number of vertices with reducepatch.m

rain6304

How do I implement the function in MATLAB? I am just beginning to use MATLAB and need some help! Thanks!

Christian

Great to learn how the snake works and how the parameter influence the result! Thank you very much!

Chris

Chris (view profile)

Hi, I am trying to run Snake3D but keep getting the following error:
"Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in Snake3D"

Does anyone know how to fix this?

IDRIS AHMED

Y Simson

Y Simson (view profile)

Signal Processing ToolBox is required for the interp() function in K=InterpolateContourPoints2D(P,nPoints)

Samuel Pedro

I don't understand how you calculate the internal force in 3d model. And I can't find a reference that supports your calculation. Can you help me?

narjes

narjes (view profile)

Hi, i try to use this code but i have a problem with "interp1 "

# ??? In an assignment A(:,matrix) = B, the number of elements in the subscript of A and the number
of columns in B must be the same.

Error in ==> C:\MATLAB6p5\work\InterpolateContourPoints2D.m
On line 40 ==> K(:,1) = interp1(dis,O(:,1),linspace(0,dis(end),nPoints*2));#

can you help me please !!!!!!

Ahmed

Ahmed (view profile)

i am try to work on active contour, but i fail although i tried different models of snake in MATLAB such as:
1-snake2D().m
2-snake().m
3-ac_segmentation().m
4-snakedeform().m

but unfortunately neither one of these methods is worked with me

please i want someone who have good experience in using it to help me how to use it.
Note:i am working on segmentation of medical H&E stains images and i need strongly to use snake to segment the nuclei(foreground) from background.

Ahmed

Ahmed (view profile)

i am try to work on active contour, but i fail although i tried different models of snake in MATLAB such as:
1-snake2D().m
2-snake().m
3-ac_segmentation().m
4-snakedeform().m

but unfortunately neither one of these methods is worked with me

please i want someone who have good experience in using it to help me how to use it.
Note:i am working on segmentation of medical H&E stains images and i need strongly to use snake to segment the nuclei(foreground) from background.

Teresa

Teresa (view profile)

Hi,
I also have a problem with the interp error and don't know how to get rid of it. I tried interp2, interp, interpn. I think interp2 works but then I get an error in
K(:,1) = interp2(dis,O(:,1),linspace(0,dis(end),nPoints*2));
K(:,2) = interp2(dis,O(:,2),linspace(0,dis(end),nPoints*2));

Does anyone find a solution and can help me?

Ahmed

Ahmed (view profile)

Inge Schie

Agnes

Agnes (view profile)

Hi,

For the issue, perhaps you should try with

   O(:,1)=interp([P(end-3:end,1);P(:,1);P(1:4,1)]',10)';
   O(:,2)=interp([P(end-3:end,1);P(:,2);P(1:4,2)]',10)';
   O=O(41:end-39,:);

Because I don't have any issue with it.
Thanks for the great work.

Felix

Felix (view profile)

Does somebody figure out how to get rid of the interp error?
I tried interpn and interp2 but was not able to get the code running.
Can somebody help me?

Error is in
InterpolateContourPoints2D

O(:,1)=interp2([P(end-3:end,1);P(:,1);P(:,1);P(1:4,1)],10);
O(:,2)=interp2([P(end-3:end,2);P(:,2);P(:,2);P(1:4,2)],10);

I tried to run the basic Example of the Snake2D but encountered this Problem with interp function

Hi.

Found a bug in InterpolateContourPoints2D possibly caused by using 'interp' function.

I think incorrect work of this basis function might lead to wrong functionality of the whole Shakes algorithm.

I can send you the example via email.

nebi

nebi (view profile)

Hi. what is the (P, Options) parameters for snake input. could you explain those. thanks

Lacey

Lacey (view profile)

Great work, and thanks for commenting so well! I'm looking to use your code, or something like it, to extract a face from the background of an image. Is there a way to use your code to train a model using a small number of training images, so the model can then be used on other images? I'd like to not have to manually click the points on the image every time. Any help would be appreciated! Thanks!

lili liliad

Hi,

I'm a MS student doing study of segmentation with paramétric snake, i search the information of Multi-Target Parametric Active Contours
Would you please help me to get those infomations?
Thank you very much.

Joy King

It's excellent. Thank you very much.

??? Error: File: Snake2D.m Line: 1 Column: 24
Unexpected MATLAB expression.
 
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in ==> imformats>find_in_registry

i am getting this error.Help?

Walid

Walid (view profile)

the code does not find interp

arron lacey

Can the GVF field be altered to create a magnetic field?

subrajeet

KYAW KYAW

Dear Dirk,
 

I am newbie in ultrasound imaging even i had few experiences in image processing and analysis other programming languages.

Currently, I am looking for a boundary detection of noisy ultrasound images but I couldn't manage to find the right one until now.I tried out using your code but the problem is still there and please advise me.

Thanks and best regards

Jack

Jack (view profile)

Hi,
Thank you very much for your great job! It is very usefull for my master thesis, but I would like to ask some questions about your toolbox.

1) If I try your example in Snake3D, the 3D Model (SphereMesh) is growing up to the out of boundary. How could it be corrected?

2) Should this 3D Model always a increasing deformable model or could it be shrinking model too?

3)Is this parameter "Delta" for baloon force always necesarry for GVF?

4)I couldnt find the parameter "Kappa" in the papers in the Literature. Could you please put the paper which contains an equation with "Kappa"?

Thanks in advance

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*Dan, the snake.m file is renamed to Snake2D.m in this version.

Dan

Dan (view profile)

I agree with Terrence.
Where is the snake.m file?

Thanks very much, I'll try it

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*Marcos Belmonte
The Triangulated Patch FV, can be constructed with the "isosurface function" on a (logical) 3D volume of a rough segmentation of your object.

Hi, congratulations on your work. I'm in a similar situation than Hsien-Chi Kuo. I want to segment more or less spherical objects in 3D but I don't know how to generate "FV". Is it necessary to build a trianguled mesh, can't it be spherical?
Thanks very much.

Hsien-Chi Kuo

Hi,

I'm a MS student doing tumor segmentation on 3D images.
Would you please tell me how to generate "FV" for snake3D?
Thank you very much.

too ym

too ym (view profile)

Hi,

% Interpolate points inbetween
O(:,1)=interp([P(end-3:end,1);P(:,1);P(:,1);P(1:4,1)],10);
O(:,2)=interp([P(end-3:end,1);P(:,2);P(:,2);P(1:4,2)],10);

In function InterpolateContourPoints2D, is it the 1 in O(:,2) should be write as 2.

 O(:,2)=interp([P(end-3:end,2);P(:,2);P(:,2);P(1:4,2)],10);

Correct me if i am wrong and thank you for your great job.

Yuanming Suo

Great tool. Well documented. Good for use to understand parametric deformable model.

Vivek

Vivek (view profile)

Hi,
i'm Vivek, doing my masters project in BioMedical image processing,
i need to use the snake for analyzing and predicting the growth of cancer tumors, could you please let me know, how to run this illustrated example in Matlab 7.8.0 R2009?

mail me your suggestion, to
vivek.acm@gmail.com

David

David (view profile)

well done, easy to read and understand.

terrence pong

where can i find the snake.m file to start?

Updates

1.7

3D snake now uses the inverse internal forces matrix

1.6

Small, Interpolate Bug Fix

1.5

Yuanming Suo reported bugs in scaling of 3D Gaussian and Mu*4. Which are corrected in this version.

1.4

Solved 3D GVF bug, and increased 3D speed.

1.3

Added parameter to keep the mesh from self-intersecting

1.2

Also added a 3D implementation. Change line image force, to Gaussian smoothed line image force.

1.1

Added GVF. Changed some minor comment

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video