7

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 !

Marcassin
  • 1,386
  • 1
  • 11
  • 21
  • Can you post information on which formulation of active contour you are using ? – navneeth Jul 09 '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 06:22

4 Answers4

12

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 here left

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 here enter image description here

Vlad
  • 4,425
  • 1
  • 30
  • 39
6

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!

  • 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 09 '14 at 20:37
0

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.

user3546025
  • 108
  • 1
  • 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 09:10
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.

HabiSoft
  • 167
  • 1
  • 8