#๐ Adding overlap behavior to randomly generated circles using cv2
9 messages ยท Page 1 of 1 (latest)
@fast inlet
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
def draw_circles(img, height, width, r_mean, r_std_dev, n, color, thickness=-1, exclude=[]):
# Draw a group of non-overlapping circles with statistical inputs
# Defaul thickness of -1 results in filled-in circles
circle_list = make_circle_list(height, width, r_mean, r_std_dev, n, exclude)
if circle_list is None:
return
for circle in circle_list:
x, y, radius = circle
center = (x, y)
cv2.circle(img, center, radius, color, thickness)
return circle_list
def create_background(height, width, color):
# Create background image of specified size and color
blank_image = np.ones((height, width, 3), np.uint8)
blank_image[:] = color
return blank_image
def save_image(img, name, directory):
ksize = [9,9] # Gaussian blur kernal size
img_blur = cv2.GaussianBlur(img, ksize, 0)
name = name + '.png'
name_blur = name + '_blur.png'
os.chdir(directory)
cv2.imwrite(name, img)
cv2.imwrite(name_blur, img_blur)
def main():
width = 1000
height = 1000
background_color = [0,0,0]
img = create_background(height, width, background_color)
# Generate AP particles
r_mean = 35
r_std_dev = 5
n = 100
color = [201, 27, 18] # [b, g, r]
AP_list = draw_circles(img, height, width, r_mean, r_std_dev, n, color)
# Generate void particles
r_mean = 15
r_std_dev = 10
n = 75
color = [53, 26, 232] # [b, g, r]
draw_circles(img, height, width, r_mean, r_std_dev, n, color, -1, AP_list)
save_dir = './output'
image_name = 'circles'
save_image(img, image_name, save_dir)
Some particularly relevant functions above
I don't know much about CV2
But, there are quite a few ways you could go about it
if you access individual pixels
you can run a specialized loop for the pixels sitting inside a circle and check for overlap
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.