如何检测和计算螺旋的转弯 [英] How to detect and count a spiral's turns

查看:63
本文介绍了如何检测和计算螺旋的转弯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测一个螺旋形弹簧并计算其线圈匝数。

I need to detect a spiral shaped spring and count its coil turns.

我尝试如下操作:

Image<Bgr, Byte> ProcessImage(Image<Bgr, Byte> img)
{ 
    Image<Bgr, Byte> imgClone = new Image<Bgr,byte>( img.Width, img.Height);
    imgClone = img.Clone();
    Bgr bgrRed = new Bgr(System.Drawing.Color.Red);


    #region Algorithm 1


    imgClone.PyrUp();
    imgClone.PyrDown();
    imgClone.PyrUp();
    imgClone.PyrDown();
    imgClone.PyrUp();
    imgClone.PyrDown();

    imgClone._EqualizeHist();
    imgClone._Dilate(20);
    imgClone._EqualizeHist();
    imgClone._Erode(10);

    imgClone.PyrUp();
    imgClone.PyrDown();
    imgClone.PyrUp();
    imgClone.PyrDown();
    imgClone.PyrUp();
    imgClone.PyrDown();

    imgClone._EqualizeHist();
    imgClone._Dilate(20);
    imgClone._EqualizeHist();
    imgClone._Erode(10);


    Image<Gray, Byte> imgCloneGray = new Image<Gray, byte>(imgClone.Width, imgClone.Height);

    CvInvoke.cvCvtColor(imgClone, imgCloneGray, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_BGR2GRAY);

    imgCloneGray = imgCloneGray.Canny(c_thresh, c_threshLink);//, (int)c_threshSize);

    Contour<System.Drawing.Point> pts = imgCloneGray.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL);

    CvInvoke.cvCvtColor(imgCloneGray, imgCloneYcc, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_GRAY2BGR);

    if (null != pts)
    {
        imgClone.Draw(pts, bgrRed, 2);
        imgClone.Draw(pts.BoundingRectangle, bgrRed, 2);
    }

    #endregion 

    return imgClone; 
}


我知道如何获得弹簧,但如何获得计数。我正在寻找算法。
我目前不寻求速度优化。

I am some how able to get the spring but how to get the counts. I am looking for algorithms. I am currently not looking for speed optimization.

这类似于手指计数。弹簧螺旋非常薄,可以使用轮廓。还有什么可以做的。 http://www.luna-arts.de/others/misc/HandsNew。 zip

This is similar like counting fingers. Spring spiral is very thin to get using contour. What else can be done. http://www.luna-arts.de/others/misc/HandsNew.zip

推荐答案

您在那儿有很好的最终二值化,但似乎仅限于此单案件。我会做一个相对简单但可能更健壮的预处理,以实现相对较好的二值化。从数学形态学出发,存在一种称为h-圆顶的变换,该变换用于通过抑制高度<f的最小值/最大值来去除无关的最小值/最大值。 h 。此操作可能在您的图像处理库中不易使用,但是实现起来并不难。为了对此预处理图像进行二值化处理,我选择了Otsu的方法,因为它是自动的并且在统计上是最优的。

You have a good final binarization over there, but it looks like to be too restricted to this single case. I would do a relatively simpler, but probably more robust, preprocessing to allow a relatively good binarization. From Mathematical Morphology, there is a transform called h-dome, which is used to remove irrelevant minima/maxima by suppressing minima/maxima of height < h. This operation might not be readily available in your image processing library, but it is not hard to implement it. To binarize this preprocessed image I opted for Otsu's method, since it is automatic and statistically optimal.

这里是h-圆顶转换后的输入图像,以及二进制图像:

Here is the input image after h-dome transformations, and the binary image:

现在,计算螺旋转弯次数 我做了非常简单的事情:我将螺旋线分开,这样我就可以将它们视为连通的组件。为了分割它们,我做了一个垂直线的形态学开口,然后是一个基本正方形的单一扩张。这将产生以下图像:

Now, to count the number of "spiral turns" I did something very simple: I split the spirals so I can count them as connected components. To split them I did a single morphological opening with a vertical line, followed by a single dilation by an elementary square. This produces the following image:

对组件进行计数得到15。由于您有13个不太接近的组件,因此此方法正确地对所有组件进行了计数。

Counting the components gives 15. Since you have 13 of them that are not too close, this approach counted them all correctly. The groups at left and right were counted as a single one.

用于执行以下步骤的完整Matlab代码:

The full Matlab code used to do these steps:

f = rgb2gray(imread('http://i.stack.imgur.com/i7x7L.jpg'));
% For this image, the two next lines are optional as they will to lead
% basically the same binary image.
f1 = imhmax(f, 30);
f2 = imhmin(f1, 30);
bin1 = ~im2bw(f2, graythresh(f2));

bin2 = bwmorph(imopen(bin1, strel('line', 15, 90)), 'dilate');

这篇关于如何检测和计算螺旋的转弯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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