Home > Academic, Matlab, Vision > Active Contour Matlab Code Demo

Active Contour Matlab Code Demo

April 7th, 2008

UPDATE:
My new post: Sparse Field Active Contours
implements quicker, more accurate active contours.

Today, I added demo code for the Hybrid Segmentation project. This segmentation algorithm (in the publications section) can be used to find the boundary of objects in images. This approach uses localized statistics and sometimes gets better results than classic methods. For an example, see the video below: The contour begins as a rectangle, but deforms over time so that it finally forms the outline of the monkey.

This can be used to segment many different classes of image. To try it out, download the demo below and run >>localized_seg_demo

localized_seg.zip

This code is based on a standard level set segmentation; it just optimizes a different energy. I’ve also made a demo which implements the well-known Chan-Vese segmentation algorithm. This technique is similar to the one above, but it looks at global statistics. This makes it more robust to initialization, but it also means that more constraints are placed on the image. Download it and see what you think! Again, unzip the file and run >>region_seg_demo

sfm_chanvese_demo.zip (New! Described Here)

regionbased_seg.zip (old and slow)

For another Matlab implementation of Active Contours check out: James Malcolm’s Webpage. He has some codes for very fast approximate implementations as well as a full numerical implementation.

  1. zhang le
    June 24th, 2008 at 07:11 | #1

    It seems works well on your special photo.It doesn’t output a satisfy result on my photo.I will do some study on your code…

  2. June 27th, 2008 at 21:04 | #2

    Also, it is true that this technique doesn’t work well on all images. Consider some of the other segmentation techniques I show [here] as well as many others in the computer vision literature!

  3. vahid
    December 16th, 2008 at 06:26 | #3

    hi
    dear
    i am msc student in iran
    i want many code about snake and level set for lip tracking
    thanks

  4. xiaochunlei
    December 19th, 2008 at 09:20 | #4

    Your methods doesn’t work well on other iamges and they cost a lot of time. Is there exist some methods to speed up?Looking forward your new improved!

  5. khusairy
    February 6th, 2009 at 06:58 | #5

    its a good code but what is alpha in the program coz i didn’t find any alpha value when i go through chan vese formulation is the alpha refer to lamda in Chan vese

  6. February 6th, 2009 at 11:06 | #6

    khusairy: Yes, \alpha = \lambda in this case. Just a simple matter of swapped notation.

  7. Med
    February 10th, 2009 at 14:10 | #7

    Hi Lankton

    Thank you for all these codes very useful.
    I have a question concerning the Chan&Vese code. I did not check other implementations, but I wanted to know whay have you used this:
    F./max(abs(F))
    is it for normalization ?
    I want to add another shape prior term, do you think it is preferable I add it to F, then it’s gonna be normalized by this form (F./max(abs(F))) or add it directly to the hole Energu F with an onther coefficient, beta, as alpha..??

    Thanks!

  8. khusairy
    February 16th, 2009 at 09:40 | #8

    Hi Shawn

    it’s me again i think the alpha in you program is not lambda but u which as in the equation u*Length(C)

    correct me if i’m wrong, thx in advance

    regards

  9. Elliot
    March 5th, 2009 at 06:01 | #9

    hi Shawn
    it is cool of you to share so many codes.they’re very useful.But,there seems something wrong in your codes on the documemt localized_seg. i try my best to find the errors(listed as follows),but fail.so put it here .looking forward to your reply,thanks!
    ……
    Error in ==> imshow at 85
    [cdata, cdatamapping, clim, map, xdata, ydata, filename, ...

    Error in ==> localized_seg>showCurveAndPhi at 136
    imshow(I,'displayrange',[0 255]); hold on;

    Error in ==> localized_seg at 116
    showCurveAndPhi(I,phi,its);

    Error in ==> localized_seg_demo at 19
    seg = localized_seg(I, m, 400); %– run segmentation

  10. April 29th, 2009 at 09:57 | #10

    I think you can correct this problem by re-writing the showCurveAndPhi function. imshow in older versions of Matlab do not handle all of the argument options that imshow has in newer versions. You could just use:
    imshow(I);
    instead of:
    imshow(I,’displayrange,’[0 255]);
    and it should work.

  11. raman
    May 5th, 2009 at 08:39 | #11

    I want to use the Active Contour Toolbox, but I’m currently having Matlab 7.1 sp1. The Active contour toolbox says it works with newer versions only. Which version should I buy??

  12. Mewada Hiren K
    July 6th, 2009 at 05:24 | #12

    In your paper “localizing region based active Contours, you did not define the kernal which is utilized for histogram separation energy measurement. So can you guide me some detaio in that algorithm….
    Thanking You,

  13. July 6th, 2009 at 09:53 | #13

    You can use any smoothing kernel you like. In my case, I used a Gaussian smoothing kernel with a standard deviation of 5.

  14. Mewada Hiren K
    July 11th, 2009 at 04:20 | #14

    Sir, i tried to designe code based on histogram separation energy and that part added as third method in your given code i.e. 1st is CV model, 2nd is Yezzi model and 3rd is i my design code, as below:
    Jin=I(upts); Hin=hist(Jin);Pin=Hin/length(Jin);, Similarly for exterior part i calculate the probabilty of pixel with in radius of defined circle.
    Function is : Bhattachrya Coefficient B= sum(sqrt(Pin(:),Pout(:)));
    t11= B*(1/Ain’-1/Aout’)); t21= K*(255-I(idx)); t22= (sqrt(Pout/Pin))/Ain’-(sqrt(Pin/Pout))/Aout’
    F=-(u-v)*(t11+t21*t22);
    but i am not gettting the result.. So it what wrong i am doing?
    Thank You Sir,,

  15. July 11th, 2009 at 11:16 | #15

    @Mewada Hiren K
    You should first implement the global Bhattacharyya (Histogram Separation) energy. This is described well in the paper by Michailovich et. al.

    Localization is a snap once you have the global version working : )

  16. Mewada Hiren K
    July 22nd, 2009 at 13:55 | #16

    Dear Sir,
    i have successfully modified your program for histogram separation based image segmentation. But it takes much time execution. Another thing i want to ask is what are the limitation of your algorithm , so that it is not segmentating object succesfully for other images. I tried much , but i could not get the answer. One request is i am also doing work in the same field. what next i can do, will please guide me.

    Thanking You

  17. July 22nd, 2009 at 13:58 | #17

    @Mewada Hiren K
    Great, good work. The execution time is a drawback of the histogram separation energy. I plan to release new codes soon which will be much faster than the implementation you are using.

    The paper discusses some of the limitations of the algorithm. From experimenting it seems that it works best in medical applications where the contour can be initialized close to the object. For processing natural images, automatic selection of the localization radius is a challenge that is still an open question.

  18. Mewada Hiren K
    August 17th, 2009 at 09:34 | #18

    Earlier i asked about the histogram separation energy in your program of Local region based image segmentation , but if i want to change the Heaviside function , then how can i do in your program , because i don’t find the function for heaviside that is mentioned as in your paper.

  19. August 17th, 2009 at 09:37 | #19

    In my implementations, I typically use $\epsilon=0$. In that case, the Heaviside function is simply 1-sign($\phi$). That cuts down on quite a few computations.

  20. Yossi
    September 1st, 2009 at 03:08 | #20

    Dear Mewada,
    Could you please share your modified program (with the histogram energy)?
    I guess it will save me a lot of time.
    Thanking you in advance,
    Regards
    @Mewada Hiren K

  1. No trackbacks yet.
Comments are closed.