任何好的 OpenCV 或 SKImage 技术来细化网格线?

Any good OpenCV or SKImage techniques to thin out gridlines?

我提取了一个干净的网格图案:

以上是我“骨架化”(或细化,或执行中轴变换)之前的网格。

下面是应用 skimage.skeletonize|medial_axis|thinmethod=lee 骨架化后的图像:

由于线条的“大胆”或“粗细”,这些似乎完全消除了网格。

是否有更好的方法来细化这些线条?

我已经修改了@Miki 的答案(实际上我的搜索显示它最初是由另一个 SO 用户在 2013 年发布的)。看看您是否可以通过调整一些参数来修改此解决方案以适合您的情况。

oElem = cv2.getStructuringElement(cv2.MORPH_RECT,(10,1))
h = cv2.morphologyEx(img, cv2.MORPH_OPEN, oElem,  iterations = 5)

oElem = cv2.getStructuringElement(cv2.MORPH_RECT,(1,10))
v = cv2.morphologyEx(img, cv2.MORPH_OPEN, oElem,  iterations = 5)

size = np.size(img)
skelh = np.zeros(img.shape,np.uint8)
skelv = np.zeros(img.shape,np.uint8)

ret,img = cv2.threshold(img,127,255,0)
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
done = False
while( not done):
    eroded = cv2.erode(h,element)
    temp = cv2.dilate(eroded,element)
    temp = cv2.subtract(h,temp)
    skelh = cv2.bitwise_or(skelh,temp)
    h = eroded.copy()
 
    if cv2.countNonZero(h)==0:
        done = True
        
done = False
while( not done):
    eroded = cv2.erode(v,element)
    temp = cv2.dilate(eroded,element)
    temp = cv2.subtract(v,temp)
    skelv = cv2.bitwise_or(skelv,temp)
    v = eroded.copy()
 
    if cv2.countNonZero(v)==0:
        done = True
        
skel = cv2.bitwise_or(skelh,skelv)