如何检测骨架图像中圆中的分段数?

2024-06-15 21:49:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个2,4,或6直径车轮的骨架图像。 我也有分支点坐标。在

我想到了两种检测不同车轮的方法:

  1. 计算圆圈内的黑色区域
  2. 绘制的计数直径

在这两种情况下,我都不知道如何实现它们。在

wheel 1wheel 2wheel 3wheel 4wheel 5

正如你所看到的,轮子并不是完美的骨架,所以很难发现差异。在

这是我用于骨骼化的代码:

首先我把图像二值化,然后放大,然后骨骼化。在

from skimage import io
import scipy
from skimage import morphology
import cv2
from scipy import ndimage as nd
import mahotas as mah
import pymorph as pm
import pymorph

complete_path = "wheel1.jpg"
gray = cv2.imread(complete_path,0)
print(gray.shape)
cv2.imshow('graybin',gray)
cv2.waitKey()

ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) 
imgbnbin = thresh
print("shape imgbnbin")
print(imgbnbin.shape)
cv2.imshow('binaria',imgbnbin)
cv2.waitKey()

element = cv2.getStructuringElement(cv2.MORPH_CROSS,(6,6)) 
graydilate = cv2.dilate(imgbnbin, element) #imgbnbin
graydilate = cv2.dilate(graydilate, element)
#graydilate = cv2.erode(graydilate, element)

cv2.imshow('dilate',graydilate)
cv2.waitKey()   

#SKELETONIZE
out = morphology.skeletonize(graydilate>0)
skel = out.astype(float)
cv2.imshow('scikitimage',skel)
cv2.waitKey()
io.imsave('wheel.jpg', skel)    
sk = skel
print(sk.shape)

原始图像:

wheel 1wheel 2wheel 3wheel 4wheel 5


Tags: from图像importaselementcv2printshape