如何在浮点位置以浮点半径在 numpy 数组中绘制圆?

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

我一直在搜索如何在具有浮点半径的浮点位置在 Numpy 数组中绘制圆。

cv2.circle 函数需要整数:

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

这在需要精度时是有限的。

使用skimage.draw。使用浮点度量可以绘制圆、圆盘、椭圆等。此处以绘制圆盘为例。

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

安装pip install scikit-image。或者看看他们的 installation documentation.