简体   繁体   中英

black area between overlapped circles in opencv - python

I am implementing "Bubbles algorithm" for classification recognition analysis. in this algorithm, we have to make mask with gaussian circles. the center of circles would be 1(255) and it will decrease over the radius which will be 0. i have problem when i put circles on each other for creating the mask, it will put a black line between circles and i can not remove it. this is my code:

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)

you can use this list as centers:

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

and the output is like this: enter image description here the problem is the black line(area) between two overlapped circles which should be removed and the joint area should be continous.

Try this...

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

the "black line" in your posted image between balls is an optical illusion . it is a local minimum and your eyes recognize that.

open your image in an image editor. take the color picker. move along a ball and into the "black line". the indicated color/brightness moves smoothly. it doesn't dip and it's not black.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM