當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。