Snake Algorithm - opencv active contour - not working so well










2















I'm actually working on a contour detection for head side. As pictures are taken in front of a white wall, I decided to run a snake (active contour model algorithm) on the picture processed with a threshold.



Problem is the snake won't fit well around the nose, the mouth, and below the mouth (as you can see in these pictures below).



//load file from disk and apply threshold
IplImage* img = cvLoadImage (file.c_str (), 0);
cvThreshold(img, img, 170, 255, CV_THRESH_BINARY);

float alpha = 0.1; // Weight of continuity energy
float beta = 0.5; // Weight of curvature energy
float gamma = 0.4; // Weight of image energy

CvSize size; // Size of neighborhood of every point used to search the minimumm have to be odd
size.width = 5;
size.height = 5;

CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER; // terminate processing after X iteration
criteria.max_iter = 10000;
criteria.epsilon = 0.1;

// snake is an array of cpt=40 points, read from a file, set by hand
cvSnakeImage(img, snake, cpt, &alpha, &beta, &gamma, CV_VALUE, size, criteria, 0);


I tried to change the alpha/beta/gamma parameters or iterations number but I didn't find a better result than output show below. I cannot understand why the nose is cut, and face is not fit around the mouth. I have enough points i guess for the curvature, but there still be some lines composed with several (>2) points.



Input Image :
Input Image - threshold



Output Snake :



  • blue : points set by hand


  • green : output snake


OutputSnake



Any help or ideas would be very appreciated.
Thanks !










share|improve this question






















  • Can you post information on which formulation of active contour you are using ?

    – nav
    Jul 9 '13 at 17:00











  • @nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

    – Marcassin
    Jul 10 '13 at 6:22















2















I'm actually working on a contour detection for head side. As pictures are taken in front of a white wall, I decided to run a snake (active contour model algorithm) on the picture processed with a threshold.



Problem is the snake won't fit well around the nose, the mouth, and below the mouth (as you can see in these pictures below).



//load file from disk and apply threshold
IplImage* img = cvLoadImage (file.c_str (), 0);
cvThreshold(img, img, 170, 255, CV_THRESH_BINARY);

float alpha = 0.1; // Weight of continuity energy
float beta = 0.5; // Weight of curvature energy
float gamma = 0.4; // Weight of image energy

CvSize size; // Size of neighborhood of every point used to search the minimumm have to be odd
size.width = 5;
size.height = 5;

CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER; // terminate processing after X iteration
criteria.max_iter = 10000;
criteria.epsilon = 0.1;

// snake is an array of cpt=40 points, read from a file, set by hand
cvSnakeImage(img, snake, cpt, &alpha, &beta, &gamma, CV_VALUE, size, criteria, 0);


I tried to change the alpha/beta/gamma parameters or iterations number but I didn't find a better result than output show below. I cannot understand why the nose is cut, and face is not fit around the mouth. I have enough points i guess for the curvature, but there still be some lines composed with several (>2) points.



Input Image :
Input Image - threshold



Output Snake :



  • blue : points set by hand


  • green : output snake


OutputSnake



Any help or ideas would be very appreciated.
Thanks !










share|improve this question






















  • Can you post information on which formulation of active contour you are using ?

    – nav
    Jul 9 '13 at 17:00











  • @nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

    – Marcassin
    Jul 10 '13 at 6:22













2












2








2


5






I'm actually working on a contour detection for head side. As pictures are taken in front of a white wall, I decided to run a snake (active contour model algorithm) on the picture processed with a threshold.



Problem is the snake won't fit well around the nose, the mouth, and below the mouth (as you can see in these pictures below).



//load file from disk and apply threshold
IplImage* img = cvLoadImage (file.c_str (), 0);
cvThreshold(img, img, 170, 255, CV_THRESH_BINARY);

float alpha = 0.1; // Weight of continuity energy
float beta = 0.5; // Weight of curvature energy
float gamma = 0.4; // Weight of image energy

CvSize size; // Size of neighborhood of every point used to search the minimumm have to be odd
size.width = 5;
size.height = 5;

CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER; // terminate processing after X iteration
criteria.max_iter = 10000;
criteria.epsilon = 0.1;

// snake is an array of cpt=40 points, read from a file, set by hand
cvSnakeImage(img, snake, cpt, &alpha, &beta, &gamma, CV_VALUE, size, criteria, 0);


I tried to change the alpha/beta/gamma parameters or iterations number but I didn't find a better result than output show below. I cannot understand why the nose is cut, and face is not fit around the mouth. I have enough points i guess for the curvature, but there still be some lines composed with several (>2) points.



Input Image :
Input Image - threshold



Output Snake :



  • blue : points set by hand


  • green : output snake


OutputSnake



Any help or ideas would be very appreciated.
Thanks !










share|improve this question














I'm actually working on a contour detection for head side. As pictures are taken in front of a white wall, I decided to run a snake (active contour model algorithm) on the picture processed with a threshold.



Problem is the snake won't fit well around the nose, the mouth, and below the mouth (as you can see in these pictures below).



//load file from disk and apply threshold
IplImage* img = cvLoadImage (file.c_str (), 0);
cvThreshold(img, img, 170, 255, CV_THRESH_BINARY);

float alpha = 0.1; // Weight of continuity energy
float beta = 0.5; // Weight of curvature energy
float gamma = 0.4; // Weight of image energy

CvSize size; // Size of neighborhood of every point used to search the minimumm have to be odd
size.width = 5;
size.height = 5;

CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER; // terminate processing after X iteration
criteria.max_iter = 10000;
criteria.epsilon = 0.1;

// snake is an array of cpt=40 points, read from a file, set by hand
cvSnakeImage(img, snake, cpt, &alpha, &beta, &gamma, CV_VALUE, size, criteria, 0);


I tried to change the alpha/beta/gamma parameters or iterations number but I didn't find a better result than output show below. I cannot understand why the nose is cut, and face is not fit around the mouth. I have enough points i guess for the curvature, but there still be some lines composed with several (>2) points.



Input Image :
Input Image - threshold



Output Snake :



  • blue : points set by hand


  • green : output snake


OutputSnake



Any help or ideas would be very appreciated.
Thanks !







c++ algorithm opencv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 9 '13 at 1:06









MarcassinMarcassin

1,1631820




1,1631820












  • Can you post information on which formulation of active contour you are using ?

    – nav
    Jul 9 '13 at 17:00











  • @nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

    – Marcassin
    Jul 10 '13 at 6:22

















  • Can you post information on which formulation of active contour you are using ?

    – nav
    Jul 9 '13 at 17:00











  • @nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

    – Marcassin
    Jul 10 '13 at 6:22
















Can you post information on which formulation of active contour you are using ?

– nav
Jul 9 '13 at 17:00





Can you post information on which formulation of active contour you are using ?

– nav
Jul 9 '13 at 17:00













@nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

– Marcassin
Jul 10 '13 at 6:22





@nav I don't know a lot about the formulation or the implementation of the active contour, I'm using snake algo from OpenCV. I heard, this implementation is not the best, i think i going to implement it by myself, maybe the best way to understand the algo...

– Marcassin
Jul 10 '13 at 6:22












4 Answers
4






active

oldest

votes


















7














A typical snake or active contour algorithm converges during a trade-off between 3 kind of cost functions: edge strength/distance (data term), spacing and smoothness (prior terms). Immediately, you may notice a connection to your "nose-problem" - the nose has high curvature. Your snake also have troubles getting into concave regions since this certainly increases its curvature compared to a convex hull.



SOLUTIONS:

A. Since your snake performance isn't better than one of a convex hull, as one of the remedies I would proceed with a simpler convex hull algorithm and then rerun it on its inverted residuals. It will get a nose right and then concavities will turn into convexities in the residuals. Or you can use convexity defect function of openCV instead of working with convexHull.



B. Another fix can be to reduce snake curvature parameter to allow it to curve around the nose sharply. Since you have little noise and you can actually clean it up a bit I see no problem of enforcing some constraints instead of making "softer" trade-offs. Perhaps a head silhouette prior model can help here too.



Below I tried to write my own snake algorithm using various distance transforms and weights of a distance parameter. The conclusion - the parameter matters more than distance metrics and does have some effect (a left picture uses smaller parameter than the right and thus cuts the nose more). The distance from contour (red) is shown with grey, snake is green.



enter image description hereleft



C. Since your background is almost solid color, invest a bit into cleaning some residual noise (use morphological operations or connected components) and just findContrours() of the clean silhouette. I implemented this last solution below: a first image has noise deleted and the second is just a contour function from openCV.
enter image description hereenter image description here






share|improve this answer
































    5














    If you want to implement by yourself, I recommend the paper "Everything you always wanted to kwon about snakes (but were afraid to ask)", By Jim Ivins and John Porrill.



    About the OpenCV implementation, I don't know it very much, but I would you suggest you to:



    • Reduce beta, so that the curvature may be stronger


    • Check the image energy. Maybe the last parameter of the function (scheme) is wrong. There are two possible values: _CV_SNAKE_IMAGE and _CV_SNAKE_GRAD. You set it to 0, if I'm not wrong, and I think 0 means _CV_SNAKE_IMAGE. So, the function will assume the input image is the energy image. Again, I'm not sure how OpenCV implements this function, but I think that when you use _CV_SNAKE_IMAGE the function assumes the input image is a gradient module image. In your case, it could make the snake avoid black regions (interpreted as low gradient module) and seek bright regions. So, try to use _CV_SNAKE_GRAD as your last parameter.


    I hope it can help you. Good luck!






    share|improve this answer























    • I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

      – Vlad
      Mar 9 '14 at 20:37


















    0














    It's been a while since I looked into the OpenCV implementation of active contours, but if I recall it correctly, it was using a greedy algorithm for energy minimization (Williams et al?). Furthermore, there are several improvements to the external force typically the edge information that improve snake convergence, e.g. the gradient vector flow field snake (GVF). The GVF external force is modeled as a liquid diffusion process to allows the snaxels (snake elements) to flow towards the image edges in areas of higher curvature and inward concavities. When active contouring, I would recommend a coarse to fine approach, that is, typically a high level process (a human or another segmentation process) will act as a seed for the initial snaxel positions, where then, the snake-deformation process will act as a fine way to delineate the ROI boundary. In applications like medical image analysis, this kind of approach would be acceptable, and even desirable. Another good snake algorithm a kin to level sets would be the Chan-Vese active contours without edges model, definitely worth checking out, and there are several examples of it in Matlab floating around the internet.






    share|improve this answer






























      -2














      Active contours are just bad - period. It looks like max flow min cut could easily solve this image segmentation problem.



      I know this was asked sometime ago but I'm that incensed with active contours in general. This page is one of the top hits on Google and I think many people will read this post in the hope that someone can do something useful with contour evolution via pdes.



      The truth is that active contours require substantial human intervention and then it only works if you have unnatural edge strengths or very high contrast.



      If your a PhD or postdoc with an interest - I beg you to find something else. I guarantee a hard viva with shocking results. Although there are seemingly good contour models out there, the source code is never made available - generalised gvf within a level set for example.



      All (binary) segmentation problems can be decomposed into a directed graph - your future employer and examiner will thank me. I urge you not to waste time on active contours.






      share|improve this answer























      • Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

        – Marcassin
        May 12 '15 at 9:10










      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538366%2fsnake-algorithm-opencv-active-contour-not-working-so-well%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      A typical snake or active contour algorithm converges during a trade-off between 3 kind of cost functions: edge strength/distance (data term), spacing and smoothness (prior terms). Immediately, you may notice a connection to your "nose-problem" - the nose has high curvature. Your snake also have troubles getting into concave regions since this certainly increases its curvature compared to a convex hull.



      SOLUTIONS:

      A. Since your snake performance isn't better than one of a convex hull, as one of the remedies I would proceed with a simpler convex hull algorithm and then rerun it on its inverted residuals. It will get a nose right and then concavities will turn into convexities in the residuals. Or you can use convexity defect function of openCV instead of working with convexHull.



      B. Another fix can be to reduce snake curvature parameter to allow it to curve around the nose sharply. Since you have little noise and you can actually clean it up a bit I see no problem of enforcing some constraints instead of making "softer" trade-offs. Perhaps a head silhouette prior model can help here too.



      Below I tried to write my own snake algorithm using various distance transforms and weights of a distance parameter. The conclusion - the parameter matters more than distance metrics and does have some effect (a left picture uses smaller parameter than the right and thus cuts the nose more). The distance from contour (red) is shown with grey, snake is green.



      enter image description hereleft



      C. Since your background is almost solid color, invest a bit into cleaning some residual noise (use morphological operations or connected components) and just findContrours() of the clean silhouette. I implemented this last solution below: a first image has noise deleted and the second is just a contour function from openCV.
      enter image description hereenter image description here






      share|improve this answer





























        7














        A typical snake or active contour algorithm converges during a trade-off between 3 kind of cost functions: edge strength/distance (data term), spacing and smoothness (prior terms). Immediately, you may notice a connection to your "nose-problem" - the nose has high curvature. Your snake also have troubles getting into concave regions since this certainly increases its curvature compared to a convex hull.



        SOLUTIONS:

        A. Since your snake performance isn't better than one of a convex hull, as one of the remedies I would proceed with a simpler convex hull algorithm and then rerun it on its inverted residuals. It will get a nose right and then concavities will turn into convexities in the residuals. Or you can use convexity defect function of openCV instead of working with convexHull.



        B. Another fix can be to reduce snake curvature parameter to allow it to curve around the nose sharply. Since you have little noise and you can actually clean it up a bit I see no problem of enforcing some constraints instead of making "softer" trade-offs. Perhaps a head silhouette prior model can help here too.



        Below I tried to write my own snake algorithm using various distance transforms and weights of a distance parameter. The conclusion - the parameter matters more than distance metrics and does have some effect (a left picture uses smaller parameter than the right and thus cuts the nose more). The distance from contour (red) is shown with grey, snake is green.



        enter image description hereleft



        C. Since your background is almost solid color, invest a bit into cleaning some residual noise (use morphological operations or connected components) and just findContrours() of the clean silhouette. I implemented this last solution below: a first image has noise deleted and the second is just a contour function from openCV.
        enter image description hereenter image description here






        share|improve this answer



























          7












          7








          7







          A typical snake or active contour algorithm converges during a trade-off between 3 kind of cost functions: edge strength/distance (data term), spacing and smoothness (prior terms). Immediately, you may notice a connection to your "nose-problem" - the nose has high curvature. Your snake also have troubles getting into concave regions since this certainly increases its curvature compared to a convex hull.



          SOLUTIONS:

          A. Since your snake performance isn't better than one of a convex hull, as one of the remedies I would proceed with a simpler convex hull algorithm and then rerun it on its inverted residuals. It will get a nose right and then concavities will turn into convexities in the residuals. Or you can use convexity defect function of openCV instead of working with convexHull.



          B. Another fix can be to reduce snake curvature parameter to allow it to curve around the nose sharply. Since you have little noise and you can actually clean it up a bit I see no problem of enforcing some constraints instead of making "softer" trade-offs. Perhaps a head silhouette prior model can help here too.



          Below I tried to write my own snake algorithm using various distance transforms and weights of a distance parameter. The conclusion - the parameter matters more than distance metrics and does have some effect (a left picture uses smaller parameter than the right and thus cuts the nose more). The distance from contour (red) is shown with grey, snake is green.



          enter image description hereleft



          C. Since your background is almost solid color, invest a bit into cleaning some residual noise (use morphological operations or connected components) and just findContrours() of the clean silhouette. I implemented this last solution below: a first image has noise deleted and the second is just a contour function from openCV.
          enter image description hereenter image description here






          share|improve this answer















          A typical snake or active contour algorithm converges during a trade-off between 3 kind of cost functions: edge strength/distance (data term), spacing and smoothness (prior terms). Immediately, you may notice a connection to your "nose-problem" - the nose has high curvature. Your snake also have troubles getting into concave regions since this certainly increases its curvature compared to a convex hull.



          SOLUTIONS:

          A. Since your snake performance isn't better than one of a convex hull, as one of the remedies I would proceed with a simpler convex hull algorithm and then rerun it on its inverted residuals. It will get a nose right and then concavities will turn into convexities in the residuals. Or you can use convexity defect function of openCV instead of working with convexHull.



          B. Another fix can be to reduce snake curvature parameter to allow it to curve around the nose sharply. Since you have little noise and you can actually clean it up a bit I see no problem of enforcing some constraints instead of making "softer" trade-offs. Perhaps a head silhouette prior model can help here too.



          Below I tried to write my own snake algorithm using various distance transforms and weights of a distance parameter. The conclusion - the parameter matters more than distance metrics and does have some effect (a left picture uses smaller parameter than the right and thus cuts the nose more). The distance from contour (red) is shown with grey, snake is green.



          enter image description hereleft



          C. Since your background is almost solid color, invest a bit into cleaning some residual noise (use morphological operations or connected components) and just findContrours() of the clean silhouette. I implemented this last solution below: a first image has noise deleted and the second is just a contour function from openCV.
          enter image description hereenter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 '14 at 1:17

























          answered Mar 6 '14 at 0:43









          VladVlad

          3,63512332




          3,63512332























              5














              If you want to implement by yourself, I recommend the paper "Everything you always wanted to kwon about snakes (but were afraid to ask)", By Jim Ivins and John Porrill.



              About the OpenCV implementation, I don't know it very much, but I would you suggest you to:



              • Reduce beta, so that the curvature may be stronger


              • Check the image energy. Maybe the last parameter of the function (scheme) is wrong. There are two possible values: _CV_SNAKE_IMAGE and _CV_SNAKE_GRAD. You set it to 0, if I'm not wrong, and I think 0 means _CV_SNAKE_IMAGE. So, the function will assume the input image is the energy image. Again, I'm not sure how OpenCV implements this function, but I think that when you use _CV_SNAKE_IMAGE the function assumes the input image is a gradient module image. In your case, it could make the snake avoid black regions (interpreted as low gradient module) and seek bright regions. So, try to use _CV_SNAKE_GRAD as your last parameter.


              I hope it can help you. Good luck!






              share|improve this answer























              • I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

                – Vlad
                Mar 9 '14 at 20:37















              5














              If you want to implement by yourself, I recommend the paper "Everything you always wanted to kwon about snakes (but were afraid to ask)", By Jim Ivins and John Porrill.



              About the OpenCV implementation, I don't know it very much, but I would you suggest you to:



              • Reduce beta, so that the curvature may be stronger


              • Check the image energy. Maybe the last parameter of the function (scheme) is wrong. There are two possible values: _CV_SNAKE_IMAGE and _CV_SNAKE_GRAD. You set it to 0, if I'm not wrong, and I think 0 means _CV_SNAKE_IMAGE. So, the function will assume the input image is the energy image. Again, I'm not sure how OpenCV implements this function, but I think that when you use _CV_SNAKE_IMAGE the function assumes the input image is a gradient module image. In your case, it could make the snake avoid black regions (interpreted as low gradient module) and seek bright regions. So, try to use _CV_SNAKE_GRAD as your last parameter.


              I hope it can help you. Good luck!






              share|improve this answer























              • I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

                – Vlad
                Mar 9 '14 at 20:37













              5












              5








              5







              If you want to implement by yourself, I recommend the paper "Everything you always wanted to kwon about snakes (but were afraid to ask)", By Jim Ivins and John Porrill.



              About the OpenCV implementation, I don't know it very much, but I would you suggest you to:



              • Reduce beta, so that the curvature may be stronger


              • Check the image energy. Maybe the last parameter of the function (scheme) is wrong. There are two possible values: _CV_SNAKE_IMAGE and _CV_SNAKE_GRAD. You set it to 0, if I'm not wrong, and I think 0 means _CV_SNAKE_IMAGE. So, the function will assume the input image is the energy image. Again, I'm not sure how OpenCV implements this function, but I think that when you use _CV_SNAKE_IMAGE the function assumes the input image is a gradient module image. In your case, it could make the snake avoid black regions (interpreted as low gradient module) and seek bright regions. So, try to use _CV_SNAKE_GRAD as your last parameter.


              I hope it can help you. Good luck!






              share|improve this answer













              If you want to implement by yourself, I recommend the paper "Everything you always wanted to kwon about snakes (but were afraid to ask)", By Jim Ivins and John Porrill.



              About the OpenCV implementation, I don't know it very much, but I would you suggest you to:



              • Reduce beta, so that the curvature may be stronger


              • Check the image energy. Maybe the last parameter of the function (scheme) is wrong. There are two possible values: _CV_SNAKE_IMAGE and _CV_SNAKE_GRAD. You set it to 0, if I'm not wrong, and I think 0 means _CV_SNAKE_IMAGE. So, the function will assume the input image is the energy image. Again, I'm not sure how OpenCV implements this function, but I think that when you use _CV_SNAKE_IMAGE the function assumes the input image is a gradient module image. In your case, it could make the snake avoid black regions (interpreted as low gradient module) and seek bright regions. So, try to use _CV_SNAKE_GRAD as your last parameter.


              I hope it can help you. Good luck!







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 26 '13 at 6:40









              Rafael H C SouzaRafael H C Souza

              1213




              1213












              • I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

                – Vlad
                Mar 9 '14 at 20:37

















              • I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

                – Vlad
                Mar 9 '14 at 20:37
















              I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

              – Vlad
              Mar 9 '14 at 20:37





              I think a pre processing stage of snakes converts input to distance transform image that represent a gradient field, not intensity gradient, that is defi ed at every point in the image as a distance to some boundary. This makes snake sensitive tothe distance to the boundary without physically connecting to it.

              – Vlad
              Mar 9 '14 at 20:37











              0














              It's been a while since I looked into the OpenCV implementation of active contours, but if I recall it correctly, it was using a greedy algorithm for energy minimization (Williams et al?). Furthermore, there are several improvements to the external force typically the edge information that improve snake convergence, e.g. the gradient vector flow field snake (GVF). The GVF external force is modeled as a liquid diffusion process to allows the snaxels (snake elements) to flow towards the image edges in areas of higher curvature and inward concavities. When active contouring, I would recommend a coarse to fine approach, that is, typically a high level process (a human or another segmentation process) will act as a seed for the initial snaxel positions, where then, the snake-deformation process will act as a fine way to delineate the ROI boundary. In applications like medical image analysis, this kind of approach would be acceptable, and even desirable. Another good snake algorithm a kin to level sets would be the Chan-Vese active contours without edges model, definitely worth checking out, and there are several examples of it in Matlab floating around the internet.






              share|improve this answer



























                0














                It's been a while since I looked into the OpenCV implementation of active contours, but if I recall it correctly, it was using a greedy algorithm for energy minimization (Williams et al?). Furthermore, there are several improvements to the external force typically the edge information that improve snake convergence, e.g. the gradient vector flow field snake (GVF). The GVF external force is modeled as a liquid diffusion process to allows the snaxels (snake elements) to flow towards the image edges in areas of higher curvature and inward concavities. When active contouring, I would recommend a coarse to fine approach, that is, typically a high level process (a human or another segmentation process) will act as a seed for the initial snaxel positions, where then, the snake-deformation process will act as a fine way to delineate the ROI boundary. In applications like medical image analysis, this kind of approach would be acceptable, and even desirable. Another good snake algorithm a kin to level sets would be the Chan-Vese active contours without edges model, definitely worth checking out, and there are several examples of it in Matlab floating around the internet.






                share|improve this answer

























                  0












                  0








                  0







                  It's been a while since I looked into the OpenCV implementation of active contours, but if I recall it correctly, it was using a greedy algorithm for energy minimization (Williams et al?). Furthermore, there are several improvements to the external force typically the edge information that improve snake convergence, e.g. the gradient vector flow field snake (GVF). The GVF external force is modeled as a liquid diffusion process to allows the snaxels (snake elements) to flow towards the image edges in areas of higher curvature and inward concavities. When active contouring, I would recommend a coarse to fine approach, that is, typically a high level process (a human or another segmentation process) will act as a seed for the initial snaxel positions, where then, the snake-deformation process will act as a fine way to delineate the ROI boundary. In applications like medical image analysis, this kind of approach would be acceptable, and even desirable. Another good snake algorithm a kin to level sets would be the Chan-Vese active contours without edges model, definitely worth checking out, and there are several examples of it in Matlab floating around the internet.






                  share|improve this answer













                  It's been a while since I looked into the OpenCV implementation of active contours, but if I recall it correctly, it was using a greedy algorithm for energy minimization (Williams et al?). Furthermore, there are several improvements to the external force typically the edge information that improve snake convergence, e.g. the gradient vector flow field snake (GVF). The GVF external force is modeled as a liquid diffusion process to allows the snaxels (snake elements) to flow towards the image edges in areas of higher curvature and inward concavities. When active contouring, I would recommend a coarse to fine approach, that is, typically a high level process (a human or another segmentation process) will act as a seed for the initial snaxel positions, where then, the snake-deformation process will act as a fine way to delineate the ROI boundary. In applications like medical image analysis, this kind of approach would be acceptable, and even desirable. Another good snake algorithm a kin to level sets would be the Chan-Vese active contours without edges model, definitely worth checking out, and there are several examples of it in Matlab floating around the internet.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 4:19









                  HabiSoftHabiSoft

                  13418




                  13418





















                      -2














                      Active contours are just bad - period. It looks like max flow min cut could easily solve this image segmentation problem.



                      I know this was asked sometime ago but I'm that incensed with active contours in general. This page is one of the top hits on Google and I think many people will read this post in the hope that someone can do something useful with contour evolution via pdes.



                      The truth is that active contours require substantial human intervention and then it only works if you have unnatural edge strengths or very high contrast.



                      If your a PhD or postdoc with an interest - I beg you to find something else. I guarantee a hard viva with shocking results. Although there are seemingly good contour models out there, the source code is never made available - generalised gvf within a level set for example.



                      All (binary) segmentation problems can be decomposed into a directed graph - your future employer and examiner will thank me. I urge you not to waste time on active contours.






                      share|improve this answer























                      • Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                        – Marcassin
                        May 12 '15 at 9:10















                      -2














                      Active contours are just bad - period. It looks like max flow min cut could easily solve this image segmentation problem.



                      I know this was asked sometime ago but I'm that incensed with active contours in general. This page is one of the top hits on Google and I think many people will read this post in the hope that someone can do something useful with contour evolution via pdes.



                      The truth is that active contours require substantial human intervention and then it only works if you have unnatural edge strengths or very high contrast.



                      If your a PhD or postdoc with an interest - I beg you to find something else. I guarantee a hard viva with shocking results. Although there are seemingly good contour models out there, the source code is never made available - generalised gvf within a level set for example.



                      All (binary) segmentation problems can be decomposed into a directed graph - your future employer and examiner will thank me. I urge you not to waste time on active contours.






                      share|improve this answer























                      • Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                        – Marcassin
                        May 12 '15 at 9:10













                      -2












                      -2








                      -2







                      Active contours are just bad - period. It looks like max flow min cut could easily solve this image segmentation problem.



                      I know this was asked sometime ago but I'm that incensed with active contours in general. This page is one of the top hits on Google and I think many people will read this post in the hope that someone can do something useful with contour evolution via pdes.



                      The truth is that active contours require substantial human intervention and then it only works if you have unnatural edge strengths or very high contrast.



                      If your a PhD or postdoc with an interest - I beg you to find something else. I guarantee a hard viva with shocking results. Although there are seemingly good contour models out there, the source code is never made available - generalised gvf within a level set for example.



                      All (binary) segmentation problems can be decomposed into a directed graph - your future employer and examiner will thank me. I urge you not to waste time on active contours.






                      share|improve this answer













                      Active contours are just bad - period. It looks like max flow min cut could easily solve this image segmentation problem.



                      I know this was asked sometime ago but I'm that incensed with active contours in general. This page is one of the top hits on Google and I think many people will read this post in the hope that someone can do something useful with contour evolution via pdes.



                      The truth is that active contours require substantial human intervention and then it only works if you have unnatural edge strengths or very high contrast.



                      If your a PhD or postdoc with an interest - I beg you to find something else. I guarantee a hard viva with shocking results. Although there are seemingly good contour models out there, the source code is never made available - generalised gvf within a level set for example.



                      All (binary) segmentation problems can be decomposed into a directed graph - your future employer and examiner will thank me. I urge you not to waste time on active contours.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 11 '15 at 22:35









                      user3546025user3546025

                      5019




                      5019












                      • Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                        – Marcassin
                        May 12 '15 at 9:10

















                      • Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                        – Marcassin
                        May 12 '15 at 9:10
















                      Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                      – Marcassin
                      May 12 '15 at 9:10





                      Hi. Thanks for your feedback. You seems to don't like ACM, but you may be right, snake may not be the best contour extraction algorithm. My problem is fixed, so I didn't need now a better solution, but I'm gonna take a look to others solutions, like you suggested. I'm not a PhD, but always interested by new algorithm.

                      – Marcassin
                      May 12 '15 at 9:10

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17538366%2fsnake-algorithm-opencv-active-contour-not-working-so-well%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                      Museum of Modern and Contemporary Art of Trento and Rovereto