【问题标题】:how to draw shapes (ellipses, rectange, circle, etc) with line width thicker than 1 pixel如何绘制线宽大于 1 像素的形状(椭圆、矩形、圆形等)
【发布时间】:2019-10-31 01:29:51
【问题描述】:

skimage.draw 模块具有绘制圆形、椭圆、线条等的功能。但是线条宽度似乎固定为 1 像素。似乎没有设置线宽的参数。

Stefan van der Walt 建议在 skimage.measure 子模块中有隐藏功能来绘制更粗的线条,但我查看了文档,只看到了具有 linewidth 参数的 profile_line 函数。我不知道这是否他的意思,或者我如何使用它来绘制一个宽度为 3 的椭圆。

那么如何将一个厚度为 3 像素的椭圆绘制到一个 numpy 图像数组(浮点类型)中?最好使用 skimage。

【问题讨论】:

    标签: width draw shapes scikit-image


    【解决方案1】:

    我会使用 draw 画一条 1 像素的粗线,然后使用 skimage.morphology.dilation 来“加粗”那条线:

    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)
    

    【讨论】:

    • (Stéfan的这句话适用于profile_line源代码,反正你只能用它来画直线。)
    • 太棒了。我还没有看过形态子模块。我会去看看它还有什么好东西。
    • 我想做的另一件事是将椭圆注释到位图上。使用draw.ellipse_perimeter() 的 1 像素 (rr,cc) 输出很容易做到这一点,但如何使用 morphology.dilation() 做到这一点?也许对于一个 3 像素宽的椭圆,在位图上绘制 3 个椭圆同样容易,每个椭圆的半径 = r - 1, r, r + 1 ??
    • 按上述方法绘制一个 boolean 零数组,然后执行target_image[ellipse_boolean] = target_annotation_color
    【解决方案2】:

    我正在尝试做同样的事情。 幸运的是我只需要画一个边界框,所以我以这种方式迭代。 不确定这种方法是否适用于其他形状。

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

    【讨论】:

      猜你喜欢
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2021-01-31
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多