如何绘制线宽大于 1 像素的形状(椭圆、矩形、圆形等)
how to draw shapes (ellipses, rectange, circle, etc) with line width thicker than 1 pixel
skimage.draw模块有画圆、椭圆、直线等功能,但线宽好像固定为1像素。好像没有设置线宽的参数。
Stefan van der Walt 建议 skimage.measure 子模块中有隐藏的功能来绘制更粗的线条,但我查看了文档,只看到 profile_line
函数确实有一个linewidth
参数。我不知道这是否是他的意思,或者我如何使用它来绘制宽度为 3 的椭圆。
那么如何将一个宽度为3像素的椭圆绘制到一个numpy图像数组(类型为float)中呢?最好使用skimage。
我会用draw
画一条1像素粗的线,然后用skimage.morphology.dilation
到"thicken"那条线:
import numpy as np
import matplotlib.pyplot as plt
from skimage import draw, morphology
image = np.zeros((128, 128))
rr, cc = draw.ellipse_perimeter(64, 64, 20, 10)
image[rr, cc] = 1
dilated = morphology.dilation(image, morphology.disk(radius=1))
fig, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(image)
ax1.imshow(dilated)
我正在尝试做同样的事情。
幸运的是,我只需要绘制一个边界框,所以我以这种方式反复进行。
不确定这种方法是否适用于其他形状。
for i in range(0,thickness):
rect = skimage.draw.rectangle_perimeter(start=(b[1]-i,b[0]-i)
,end(b[3]+i,b[2]+i),shape=(1024,1024))
skimage.draw.set_color(img_with_box,rect,(1.0,-1,-1))
skimage.draw模块有画圆、椭圆、直线等功能,但线宽好像固定为1像素。好像没有设置线宽的参数。
Stefan van der Walt 建议 skimage.measure 子模块中有隐藏的功能来绘制更粗的线条,但我查看了文档,只看到 profile_line
函数确实有一个linewidth
参数。我不知道这是否是他的意思,或者我如何使用它来绘制宽度为 3 的椭圆。
那么如何将一个宽度为3像素的椭圆绘制到一个numpy图像数组(类型为float)中呢?最好使用skimage。
我会用draw
画一条1像素粗的线,然后用skimage.morphology.dilation
到"thicken"那条线:
import numpy as np
import matplotlib.pyplot as plt
from skimage import draw, morphology
image = np.zeros((128, 128))
rr, cc = draw.ellipse_perimeter(64, 64, 20, 10)
image[rr, cc] = 1
dilated = morphology.dilation(image, morphology.disk(radius=1))
fig, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(image)
ax1.imshow(dilated)
我正在尝试做同样的事情。 幸运的是,我只需要绘制一个边界框,所以我以这种方式反复进行。 不确定这种方法是否适用于其他形状。
for i in range(0,thickness):
rect = skimage.draw.rectangle_perimeter(start=(b[1]-i,b[0]-i)
,end(b[3]+i,b[2]+i),shape=(1024,1024))
skimage.draw.set_color(img_with_box,rect,(1.0,-1,-1))