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


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

用法:

skimage.draw.ellipse(r, c, r_radius, c_radius, shape=None, rotation=0.0)

生成椭圆内的像素坐标。

参数

r, c双倍的

椭圆的中心坐标。

r_radius, c_radius双倍的

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

shape元组,可选

用于确定输出像素坐标的最大范围的图像形状。这对于超出图像大小的椭圆很有用。默认情况下,使用椭圆的完整范围。长度必须至少为 2。只有前两个值用于确定范围。

rotation浮点数,可选(默认为 0。)

在逆时针方向设置椭圆旋转(-PI,PI)范围内的椭圆旋转(旋转),因此PI /2度表示交换椭圆轴

返回

rr, ccint的ndarray

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

注意

椭圆方程:

((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 +
((x * sin(alpha) - y * cos(alpha)) / y_radius) ** 2 = 1

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

>>> rr, cc = ellipse(1, 2, 3, 6)
>>> img = np.zeros((6, 12), dtype=np.uint8)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1]], dtype=uint8)

例子

>>> from skimage.draw import ellipse
>>> img = np.zeros((10, 12), dtype=np.uint8)
>>> rr, cc = ellipse(5, 6, 3, 5, rotation=np.deg2rad(30))
>>> 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, 0],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

相关用法


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