Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing true filled circle on an image

I have an image which I define like the following:

img = np.zeros(474,474)

I would like to draw true filled circles and not polygonal approximations of circles on this image at different coordinates as centre and of a fixed radius. For example, I want to draw two circles with centres (100,200) and (150,372) with radius 2 pixels. What I am expecting is that after plotting the circles, the entries of the original image img should change to all ones where the circle is present. I tried opencv cv.circlemodule as well as skimage.draw.circle module but they generate some polynomial approximation of circle. I was also trying the following in matplotlib but I don't seem to understand how to plot it on my image img. Any help would be appreciated.

from matplotlib.patches import Circle
img=np.zeros(474,474)
fig = plt.figure()
ax = fig.add_subplot(111)
centers = [(100,200),(150,372)]
for i in range(len(centers)):
    Circle((centers[i][0],centers[i][1]), radius= 2)
like image 327
Silver moon Avatar asked Nov 19 '25 20:11

Silver moon


1 Answers

draw circles in the img.

import cv2
import numpy as np

img = np.zeros([474, 474])

cv2.circle(img, (100,100), 5, 255, -1)
cv2.circle(img, (200,200), 30, 255, -1)

cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
like image 90
Junhee Shin Avatar answered Nov 21 '25 09:11

Junhee Shin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!