Jav
Jav

Reputation: 1607

How to draw a circle in a numpy array with floating point radius at floating point position?

I've been searching on how to draw a circle in a Numpy array at floating point position with a floating point radius.

The cv2.circle function expects integers:

cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]]) ->  img

and this is limiting when precision is required.

Upvotes: 1

Views: 1718

Answers (1)

Jav
Jav

Reputation: 1607

Using skimage.draw. It is possible to draw circles, disks, ellipsis and more, using floating point measures. Example here with drawing a disk.

import numpy as np
import skimage.draw

height, width = 50, 50
target = np.zeros((height, width), dtype=np.uint8)
x, y = 21.5, 18.2
radius = 14.3
target[skimage.draw.disk((x,y), radius=radius)] = 1

Installation with pip install scikit-image. Or look at their installation documentation.

Upvotes: 4

Related Questions