如何找到谐波图像中孔的位置?

我试图找到规则形状的图像中的缺陷或变化,因此 enter image description here

我想在里面找到变形的位置,它可能会改变它的位置,这样 enter image description here

我尝试通过图像的像素和 python 中 x 和 y 坐标的位置来做到这一点

    imgdata = image.getdata()
    imgWidth,imgHeight = image.size
    x_pos = 0
    y_pos = 1
    pixel_value = []
    x = []
    y = []
    
    for item in imgdata:
        item = str(item)
    
        if (x_pos) == imgWidth:
            x_pos = 1
            y_pos += 1
        else:
            x_pos += 1
    
        if item[1] != 0:
            pixel_value.append(item[0])
            x.append(x_pos)
            y.append(y_pos)
    
    pixel_value,x,y = zip(*sorted(zip(pixel_value,y),reverse=True))

df = pd.DataFrame({'target':pixel_value,'X': x,'Y': y })

但这定位像素和像素位置而我找不到hols的位置? 如果有人推荐找到 hols 的最佳方式,我将不胜感激 非常感谢

heartear15 回答:如何找到谐波图像中孔的位置?

您可以尝试重复填充,例如使用红色,从图像中的许多种子点开始,然后计算产生的红色像素的数量。 “洞”中会更大,然后您可以找到红色像素的面积和质心。

您必须将种子点分布在整个图像上,其距离可能小于当前白色格子孔的半径。

enter image description here

我认为这种方法不会那么快,因此您可能需要使用多处理。


您还可以通过将图像放入 Numpy 数组然后使用:

rowSums = np.sum(image,axis=1)

enter image description here

在格子中有孔的地方,一行中会有更多的白色像素和更少的黑色像素,因此总和会更高。

,

enter image description here

enter image description here

通过像素的总和,我可以采取与您类似的方式,因为我是第一种方式,现在我有了行和列中像素最大值的总和,如何达到 a 的 x 和 y 坐标最大像素值的范围?我的意思是有没有建议计算图表中的增加范围?

本文链接:https://www.f2er.com/5098.html

大家都在问