使用图像处理计算弯管的曲率(霍夫变换抛物线检测)

Compute curvature of a bent pipe using image processing (Hough transform parabola detection)

我正在尝试设计一种方法来检测此管道的曲率。我尝试应用 hough 变换并发现检测到的线,但它们不位于管道表面,因此将其平滑以适合 beizer 曲线不起作用。请建议一些好的方法来开始像这样的图像。[

霍夫变换检测直线得到的图像如下 [ 我正在使用标准的 Matlab 代码进行概率霍夫变换线检测,生成围绕结构的线段。本质上,管道的形状类似于抛物线,但对于 hough 抛物线检测,我需要在检测之前提供该点的偏心率。请提出一种沿着曲率找到离散点的好方法,这些点可以适合抛物线。我已经给 opencv 和 ITK 打了标签,所以如果有可以在这张特定图片上实现的功能,请建议功能,我会尝试一下看看结果。

img = imread('test2.jpg');
rawimg = rgb2gray(img);
 [accum, axis_rho, axis_theta, lineprm, lineseg] = Hough_Grd(bwtu, 8, 0.01);
figure(1); imagesc(axis_theta*(180/pi), axis_rho, accum); axis xy;
 xlabel('Theta (degree)'); ylabel('Pho (pixels)');
 title('Accumulation Array from Hough Transform');
  figure(2); imagesc(bwtu); colormap('gray'); axis image;
  DrawLines_2Ends(lineseg);
  title('Raw Image with Line Segments Detected');

图像的边缘图如下 and the result generated after applying Hough transform on edge map is also not good. I was thinking a solution that does general parametric shape detection like this curve can be expressed as a family of parabola and so we do a curve fitting to estimate the coefficients as it bends to analyze it's curvature. I need to design a real time procedure so please suggest anything in this direction.

您可以找到倒置边缘图图像的连通分量 (CC)。然后,您可以使用区域属性以某种方式过滤这些组件,例如,根据它们的像素数。这是我使用给定的 Octave 代码获得的连接组件。 现在,您可以使用 nlinfit 或任何合适的方法为这些 CC 中的每一个拟合模型。

im = imread('uFBtU.png');
gr = rgb2gray(uint8(im));
er = imerode(gr, ones(3)) < .5;

[lbl, n] = bwlabel(er, 8);
imshow(label2rgb(lbl))

我建议采用以下方法:

第一阶段:生成管道分段。

  1. 对图像执行阈值处理。
  2. 在阈值图像中找到连通分量。
  3. 搜索表示管道的连通分量。 代表管道的连接组件应该有一个边缘图,它分为顶部和底部边缘(见附图)。 顶部和底部边缘的大小应该相似,并且彼此之间的距离应该相对恒定。换句话说,它们的每像素距离的方差应该很小。

第二阶段-提取曲线​​

在这个阶段,你应该提取曲线的点来进行Beizer拟合。 您可以在顶部边缘或底部边缘执行此计算。 另一种选择是在管道分段的骨架上进行。

结果

管道分割。顶部和底部边缘分别用蓝色和红色标记。

代码

I = mat2gray(imread('ILwH7.jpg'));
im = rgb2gray(I);

%constant values to be used later on
BW_THRESHOLD = 0.64;
MIN_CC_SIZE = 50;
VAR_THRESHOLD = 2;
SIMILAR_SIZE_THRESHOLD = 0.85;

%stage 1 - thresholding & noise cleaning
bwIm = im>BW_THRESHOLD;
bwIm = imfill(bwIm,'holes');
bwIm = imopen(bwIm,strel('disk',1));


CC = bwconncomp(bwIm);
%iterates over the CC list, and searches for the CC which represents the
%pipe
for ii=1:length(CC.PixelIdxList)
    %ignore small CC
    if(length(CC.PixelIdxList{ii})<50)
        continue;
    end
    %extracts CC edges
    ccMask = zeros(size(bwIm));
    ccMask(CC.PixelIdxList{ii}) = 1;
    ccMaskEdges = edge(ccMask);

    %finds connected components in the edges mat(there should be two).
    %these are the top and bottom parts of the pipe.
    CC2 = bwconncomp(ccMaskEdges);
    if length(CC2.PixelIdxList)~=2
        continue;
    end

    %tests that the top and bottom edges has similar sizes
    s1 = length(CC2.PixelIdxList{1});
    s2 = length(CC2.PixelIdxList{2});
    if(min(s1,s2)/max(s1,s2) < SIMILAR_SIZE_THRESHOLD)
        continue;
    end

    %calculate the masks of these two connected compnents
    topEdgeMask = false(size(ccMask));
    topEdgeMask(CC2.PixelIdxList{1}) = true;
    bottomEdgeMask = false(size(ccMask));
    bottomEdgeMask(CC2.PixelIdxList{2}) = true;

    %tests that the variance of the distances between the points is low
    topEdgeDists = bwdist(topEdgeMask);
    bottomEdgeDists = bwdist(bottomEdgeMask);
    var1 = std(topEdgeDists(bottomEdgeMask));
    var2 = std(bottomEdgeDists(topEdgeMask));

    %if the variances are low - we have found the CC of the pipe. break!
    if(var1<VAR_THRESHOLD && var2<VAR_THRESHOLD)
        pipeMask = ccMask;
        break;
    end


end

%performs median filtering on the top and bottom boundaries.
MEDIAN_SIZE =5;
[topCorveY, topCurveX] = find(topEdgeMask);
topCurveX = medfilt1(topCurveX);
topCurveY = medfilt1(topCurveY);
[bottomCorveY, bottomCurveX] = find(bottomEdgeMask);
bottomCurveX = medfilt1(bottomCurveX);
bottomCorveY = medfilt1(bottomCorveY);

%display results
imshow(pipeMask); hold on;
plot(topCurveX,topCorveY,'.-');
plot(bottomCurveX,bottomCorveY,'.-');

评论

  1. 在这个具体的例子中,通过阈值化获取管道分割是比较容易的。在某些场景中,它可能更复杂。在这些情况下,您可能希望使用区域增长算法来生成管道分段。

  2. 检测表示管道的连接组件可以通过使用更多的启发式方法来完成。例如 - 它边界的局部曲率应该很低。