任何好的 OpenCV 或 SKImage 技术来细化网格线? [英] Any good OpenCV or SKImage techniques to thin out gridlines?

查看:52
本文介绍了任何好的 OpenCV 或 SKImage 技术来细化网格线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have extracted a clean grid pattern:

这是我骨架化"之前的网格(或瘦,或执行中轴变换).

This above is the grid before I "skeletonize" (or thin, or perform the medial axis transform).

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

An below is the image after an application of skimage.skeletonize|medial_axis|thin or method=lee for the skeletonize:

由于大胆",这些似乎完全消除了网格.或厚度"的行.

These seem to eliminate the grid entirely due to the "boldness" or "thickness" of the lines.

有没有一种首选的方法来细化这些线条?

Is there a preferred method to thin out these lines?

推荐答案

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

I have modified @Miki's answer (actually my search revealed that it was originally posted by another SO user in 2013). See if this solution is something that you could modify, by maybe tweaking a few parameters, to work for your case.

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)

这篇关于任何好的 OpenCV 或 SKImage 技术来细化网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆