我有一个画有2,4或6个直径的轮子的骨架图像。 我也有分支坐标。
我想到了两种检测不同车轮的方法:
在这两种情况下,我都不知道如何实施它们。
正如你所看到的,车轮不是完美的镂空,所以检测差异更难。
这是我用于骨架化的代码:
首先,我将图像二值化,然后进行扩张,然后进行骨架化。
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)
原始图片: