【问题标题】:black area between overlapped circles in opencv - pythonopencv中重叠圆圈之间的黑色区域 - python
【发布时间】:2021-03-22 19:48:24
【问题描述】:

我正在实施“气泡算法”进行分类识别分析。 在这个算法中,我们必须用高斯圆制作掩码。 圆心将是 1(255),它会在半径为 0 的范围内减小。 当我将圆圈放在彼此上以创建蒙版时,我遇到了问题,它会在圆圈之间放置一条黑线,我无法将其移除。 这是我的代码:

def make_gaussian(circle_center, Gaussian_base):
for t in range(circle_center[1] - radius, circle_center[1] + radius):
    for tt in range(circle_center[0] - radius, circle_center[0] + radius):
        distance = int(compute_distance(tt, circle_center[0], t, circle_center[1]))
        if distance < radius  :
            value = int(((radius - distance) * (1 / radius)) * 255)
            if Gaussian_base[t][tt].mean() < value:
            Gaussian_base[t][tt] = [value, value, value]
return Gaussian_base

Gaussian_base = np.zeros((height, width, 3), np.uint8)
for s in centers:
    #xmin, ymin, xmax, ymax
    Gaussian_base = make_gaussian(s, Gaussian_base)
cv2.imwrite('gaussianMask.jpg', Gaussian_base)

您可以将此列表用作中心:

centers = [(139, 102), (223, 193), (94, 385), (205, 301), (90, 147), (190, 209), (45, 349), (193, 259), (110, 343), (159, 99)]

输出如下: enter image description here 问题是两个重叠圆圈之间的黑线(区域)应该被移除并且连接区域应该是连续的。

【问题讨论】:

    标签: python opencv geometry mask gaussian


    【解决方案1】:

    试试这个...

    def make_gaussian(circle_center, Gaussian_base):
        for t in range(circle_center[1] - radius, circle_center[1] + radius):
            for tt in range(circle_center[0] - radius, circle_center[0] + radius):
                distance = int(compute_distance(tt, circle_center[0], t, circle_center[1]))
                if distance < radius  :
                    value = int(((radius - distance) * (1 / radius)) * 200)
                    #if Gaussian_base[t][tt].mean() < value:
                    Gaussian_base[t][tt] += np.array([value, value, value], dtype=np.uint8)
        return Gaussian_base
    

    【讨论】:

      【解决方案2】:

      your posted image 中球之间的“黑线”是一种视觉错觉。这是一个局部最小值,您的眼睛可以识别。

      在图像编辑器中打开您的图像。拿取色器。沿着球移动并进入“黑线”。指示的颜色/亮度平滑移动。它不下垂,也不黑。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-02
        • 1970-01-01
        • 2020-08-28
        • 2014-10-31
        • 2021-03-21
        • 2020-06-24
        • 2012-06-07
        • 1970-01-01
        相关资源
        最近更新 更多