version 1.7.0.0 (40.9 KB) by
Dirk-Jan Kroon

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

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

Dirk-Jan Kroon (2021). Snake : Active Contour (https://www.mathworks.com/matlabcentral/fileexchange/28149-snake-active-contour), MATLAB Central File Exchange. Retrieved .

Created with
R2010a

Compatible with any release

**Inspired:**
Eye Disk Segmentation Using Luminance Channel and Active Contour

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

YIFAN YANGHsu Yung-Cheng佳男 杨Maxime Norekusmae16Gurjot Singh SandhuGurjot Singh SandhuI am trying to use the algorithm to extract the instantaenous frequency of audio signals. The snake always connects to a closed structure, for example a loop. Any idea what I could do, to get a non closed curve?

creation gamesGuilherme CorreiaVeeEee TechVeeEee Techhanwen kangnice，can directly be used, thx! good work.

BGTo obtain a separate kernel in two dimensions, consider using an SVD of the filter taps. The scaled outer product for the top one is best in a least squares sense. For higher dimensions, it is possible to consider a higher order SVD with tensors.

xinlanweimeiWael Emishi have problem in result......the efficiency of segmented image is very low...can you help me??

snehal jaipurkarSir how to save the segmented image after applying snake model in Matlab??

song yongbinJ de Ruijteranggi negocorentin tisserandHi, I'm trying the example in Snake2D.

When I launch my programm, there is an error which is : 'undefined variable or function J'. Indeed, when I look at the script:

Irgb(:,:,1)=I;

Irgb(:,:,2)=I;

Irgb(:,:,3)=J;

figure, imshow(Irgb,[]);

hold on; plot([O(:,2);O(1,2)],[O(:,1);O(1,1)]);

[O,J]=Snake2D(I,P,Options);

the point That Irgb(:,:,3)=J; concerns me, since J is an output of Snake2D, so how could to define it?

thank you for your answer.

Sreenath BalakrishnanTurgut S.dinial utamiChris VolpeHi 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 yangMarlonshivangi bplease 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

Marlonvasanthselvakumar Ri 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 lithis is very useful for me .thank you.

Zizhao Zhangkeerthi vkavindra jainafter the energy optimized output red line area how can i extract my selected image automatically

Yousef MazaheriDirk-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

Meghana DineshI 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.

Ishaan MarkaleHi,

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!!

ChristianIn 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

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

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

ChrisHi, 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 AHMEDY SimsonSignal Processing ToolBox is required for the interp() function in K=InterpolateContourPoints2D(P,nPoints)

32sthideI 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?

narjesHi, 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 !!!!!!

Ahmedi 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.

Ahmedi 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.

TeresaHi,

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?

AhmedInge SchieAgnesHi,

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.

FelixDoes 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

Dmitry SorokinHi.

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.

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

LaceyGreat 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 liliadHi,

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 KingIt's excellent. Thank you very much.

Qasim ul-haque??? 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?

Walidthe code does not find interp

arron laceyCan the GVF field be altered to create a magnetic field?

subrajeetKYAW KYAWDear 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

JackHi,

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*Dan, the snake.m file is renamed to Snake2D.m in this version.

DanI agree with Terrence.

Where is the snake.m file?

Marcos BelmonteThanks very much, I'll try it

Dirk-Jan Kroon*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.

Marcos BelmonteHi, 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 KuoHi,

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 ymHi,

% 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 SuoGreat tool. Well documented. Good for use to understand parametric deformable model.

VivekHi,

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

Davidwell done, easy to read and understand.

terrence pongwhere can i find the snake.m file to start?