Silver moon
Silver moon

Reputation: 229

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)

Upvotes: 3

Views: 3224

Answers (2)

Crapsy
Crapsy

Reputation: 356

When drawing a circle in OpenCV, there are several parameters that can be chosen, one of them is used to define the type of the circle boundary, you have 4 types:

  • Filled
  • 4-connected line
  • 8-connected line
  • antialiased line

You can see the different effect on the following image (in same order) enter image description here

An example code (in C++)

circle(src,cv::Point(300,300), 10, Scalar(0,0,255), 1, FILLED);

Upvotes: 2

Junhee Shin
Junhee Shin

Reputation: 758

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()

Upvotes: 4

Related Questions