在图像中定位桥状结构的端点

| 如何在图像中找到类似桥梁的结构的端点? 以下是广义表示。 我有一组图像,看起来像您在左栏中看到的,如上图所示。我试图检测/定位的实际上是上图中右栏中显示的两个端点。就像定位“桥”的“两个端点”一样。 我已经应用了一些基本的形态学运算;但是,要么我做错了,要么这些基本形态学操作在这种情况下不起作用。 (我尝试将其制作成骨骼;但是,一旦骨骼形成,我似乎无法检测到具有三个边缘的十字架)。 编辑 感谢您先前的建议;但是,看起来原始图像集无法像我之前绘制的那样完全归纳。 我已将此问题附上最新更新。下面是一个更详细的表示,包括原始的分割区域和经过“细化”形态学操作的相应图像。同样,左侧是最初分割的区域;而在右侧将是要检测的点。     
已邀请:
        这是一个代码示例,用于在对图像进行骨架化之后定位分支点:
import pymorph as m
import mahotas
from numpy import array

image = mahotas.imread(\'1.png\') # load image

b1 = image[:,:,1] < 150 # make binary image from thresholded green channel

b2 = m.thin(b1) # create skeleton
b3 = m.thin(b2, m.endpoints(\'homotopic\'), 15) # prune small branches, may need tuning

# structuring elements to search for 3-connected pixels
seA1 = array([[False,  True, False],
       [False,  True, False],
       [ True, False,  True]], dtype=bool)

seB1 = array([[False, False, False],
       [ True, False,  True],
       [False,  True, False]], dtype=bool)

seA2 = array([[False,  True, False],
       [ True,  True,  True],
       [False, False, False]], dtype=bool)

seB2 = array([[ True, False,  True],
       [False, False, False],
       [False,  True, False]], dtype=bool)

# hit or miss templates from these SEs
hmt1 = m.se2hmt(seA1, seB1)
hmt2 = m.se2hmt(seA2, seB2)

# locate 3-connected regions
b4 = m.union(m.supcanon(b3, hmt1), m.supcanon(b3, hmt2))

# dilate to merge nearby hits
b5 = m.dilate(b4, m.sedisk(10))

# locate centroids
b6 = m.blob(m.label(b5), \'centroid\')

outputimage = m.overlay(b1, m.dilate(b6,m.sedisk(5)))
mahotas.imsave(\'output.png\', outputimage)  
    
        使用Python,NumPy,Pymorph和Mahotas的解决方案:
import pymorph as m
import mahotas
from numpy import where, reshape

image = mahotas.imread(\'input.png\') # Load image

b1 = image[:,:,0] < 100 # Make a binary image from the thresholded red channel
b2 = m.erode(b1, m.sedisk(4)) # Erode to enhance contrast of the bridge
b3 = m.open(b2,m.sedisk(4)) # Remove the bridge
b4 = b2-b3 # Bridge plus small noise
b5 = m.areaopen(b4,1000) # Remove small areas leaving only a thinned bridge
b6 = m.dilate(b3)*b5 # Extend the non-bridge area slightly and get intersection with the bridge.

#b6 is image of end of bridge, now find single points
b7 = m.thin(b6, m.endpoints(\'homotopic\')) # Narrow regions to single points.
labelled = m.label(b7) # Label endpoints.

x1, y1 = reshape(where(labelled == 1),(1,2))[0]
x2, y2 = reshape(where(labelled == 2),(1,2))[0]

outputimage = m.overlay(b1, m.dilate(b7,m.sedisk(5)))
mahotas.imsave(\'output.png\', outputimage)
    
        在这里,您在Mathematica中有一个代码示例,可能不是最佳示例:
f[i_] := 
   Module[{t, i2, w, z, neighbours, i3, cRed}, 
  (t = Thinning[ColorNegate@i, 15]; 
   i2 = ImageData@Binarize[ DeleteSmallComponents[
        ImageSubtract[t, Dilation[Erosion[t, 1], 1]], 100], .1];

    For[w = 2, w < Dimensions[i2][[1]], w++,
     For[z = 2, z < Dimensions[i2][[2]], z++,
      If[i2[[w, z]] == 1 && i2[[w + 1, z + 1]] == 1, 
         i2[[w, z + 1]] = i2[[w + 1, z]] = 0];
      If[i2[[w, z]] == i2[[w - 1, z - 1]] == 1, 
         i2[[w, z - 1]] = i2[[w - 1, z]] = 0];
      If[i2[[w, z]] == i2[[w + 1, z - 1]] == 1, 
         i2[[w, z - 1]] = i2[[w + 1, z]] = 0];
      If[i2[[w, z]] == i2[[w - 1, z + 1]] == 1, 
         i2[[w, z + 1]] = i2[[w - 1, z]] = 0];
      ]
     ];

    neighbours[l_, k_, j_] := 
      l[[k - 1, j]] +     l[[k + 1, j]] +     l[[k, j + 1]] + l[[k, j - 1]] + 
      l[[k + 1, j + 1]] + l[[k + 1, j - 1]] + l[[k - 1, j + 1]] + 
      l[[k - 1, j - 1]];

    i3 = Table[
      If[i2[[w, z]] ==1,neighbours[i2, w, z], 0],{w,2,Dimensions[i2][[1]]-1}, 
                                                 {z,2,Dimensions[i2][[2]]-1}];
    cRed = 
     ColorNegate@Rasterize[Graphics[{Red, Disk[]}], ImageSize -> 15];

    ImageCompose[
     ImageCompose[i, 
      cRed, {#[[2]], Dimensions[i2][[1]] - #[[1]]} &@
       Position[i3, 1][[1]]], 
      cRed, {#[[2]], Dimensions[i2][[1]] - #[[1]]} &@
       Position[i3, 1][[2]]])];
    
        我想到了一种通用方法: 1)跟踪轮廓并将其变成路径。因此,有一条路径可以围绕整个形状,由线段组成 2)寻找词干-路径上线段大致平行一段距离的位置(例如八度树或kdtree等空间索引将有助于保持搜索局部化) 3)沿某个方向走,直到两侧突然分开。那是茎的终点 4)沿着另一个方向走,找到另一个终点     
        您也可以尝试使用包含内部像素值之和的滤镜在图像上运行移动窗口。调整大小,使之等于桥宽度的两倍。从桥上驶向海岸时,您应该期望看到一个相当陡峭的过渡。     
        发现的一个有趣的特征是骨骼中的交点,该交点具有与之关联的对象的互补序列的距离函数的最小值。 X-在输入图像中设置为黑色的对象 D(X)-对象X的距离函数 D(〜X)-对象补码的距离函数-通常类似于自身设置的对象骨架。 因此,这里的基本直觉是,对象X的拓扑结构使得靠近沉重的头部时,人们会感到pin缩-您肯定会在骨骼中拥有接合点的位置,而同时X的低值物体补体的距离函数。此处的颈部或捏处在接合点处产生最小值。 也许这个想法需要一些调整-但我想一个人可以解决。     

要回复问题请先登录注册