当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python skimage.draw.ellipse_perimeter用法及代码示例


用法:

skimage.draw.ellipse_perimeter(r, c, r_radius, c_radius, orientation=0, shape=None)

生成椭圆周长坐标。

参数

r, cint

椭圆的中心坐标。

r_radius, c_radiusint

次要和主要半轴。 (r/r_radius)**2 + (c/c_radius)**2 = 1

orientation双,可选

顺时针方向的长轴方向,以弧度表示。

shape元组,可选

用于确定输出像素坐标的最大范围的图像形状。这对于超出图像大小的椭圆很有用。如果没有,则使用椭圆的全部范围。长度必须至少为 2。只有前两个值用于确定输入图像的范围。

返回

rr, cc(N,)int的ndarray

属于椭圆周长的像素的索引。可用于直接索引到数组中,例如img[rr, cc] = 1

参考

1

A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012 http://members.chello.at/easyfilter/Bresenham.pdf

例子

>>> from skimage.draw import ellipse_perimeter
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = ellipse_perimeter(5, 5, 3, 4)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

注意的位置skimage.draw.ellipse未指定形状也可以有负值,因为这在飞机上是正确的。另一方面,之后将这些椭圆位置用于图像可能会导致出现在图像的另一侧,因为image[-1, -1] = image[end-1, end-1]

>>> rr, cc = ellipse_perimeter(2, 3, 4, 5)
>>> img = np.zeros((9, 12), dtype=np.uint8)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]], dtype=uint8)

相关用法


注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.draw.ellipse_perimeter。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。