Snake算法 - OpenCV的主动轮廓 - 不工作这么好 [英] Snake Algorithm - opencv active contour - not working so well

查看:4936
本文介绍了Snake算法 - OpenCV的主动轮廓 - 不工作这么好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我工作的一个轮廓检测头的一面。因为照片拍摄于一个白色的墙壁前,我决定跑<一href="http://opencv.willowgarage.com/documentation/motion_analysis_and_object_tracking.html#snakeimage"与阈值处理的图像相对=nofollow>蛇(主动轮廓模型算法)。

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);

我试图改变α/β/伽玛参数或迭代号码,但我没有找到比下面的输出显示了较好的效果。我不明白为什么鼻子被切断,脸不适合口周围。我有足够的积分,我想为弧度,但仍然有一些行与一些(> 2)点组成。

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 :

输出蛇:

  • 蓝:分手动设置

  • blue : points set by hand

绿色:输出蛇

任何帮助或想法将是非常美联社preciated。 谢谢!

Any help or ideas would be very appreciated. Thanks !

推荐答案

一个典型的蛇或主动轮廓算法3种成本函数之间的权衡过程中收敛:边缘强度/距​​离(数据项),间距和平滑度(前计算)。随即,您可能会注意到你的鼻子问题的连接 - 鼻子有高曲率。你的蛇也有烦恼进入凹形区域,因为这肯定会增加它的曲率比作一个凸包。

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.

解决方案:
答:由于你的蛇性能并不比一个凸包的一个更好的,因为我会着手进行简单的凸包算法的补救措施之一,然后重新运行它在它的倒残差。它会得到一个鼻子右侧,然后凹陷会变成在残差凸。或者你也可以使用,而不是用<工作的OpenCV凸性缺陷的功能href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=convexhull#cv2.convexHull"相对=nofollow>凸形轮廓。

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.

℃。由于你的背景几乎是纯色,投资有点成清洁残留一些噪声(使用形态学操作或连接组件)和公正的<一个href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findco#cv.FindContours"相对=nofollow> findContrours()干净的剪影。我实现了下面这最后的解决方案:第一图像删除了噪声,二是刚刚从OpenCV的轮廓功能。

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.

这篇关于Snake算法 - OpenCV的主动轮廓 - 不工作这么好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆