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


Python skimage.draw.disk用法及代碼示例

用法:

skimage.draw.disk(center, radius, *, shape=None)

生成圓內像素的坐標。

參數

center元組

磁盤的中心坐標。

radius雙倍的

磁盤半徑。

shape元組,可選

圖像形狀為大小為 2 的元組。確定輸出像素坐標的最大範圍。這對於超出映像大小的磁盤很有用。如果沒有,則使用磁盤的完整範圍。該形狀可能會導致負坐標和環繞行為。

返回

rr, ccint的ndarray

磁盤的像素坐標。可用於直接索引到數組中,例如img[rr, cc] = 1

例子

>>> import numpy as np
>>> from skimage.draw import disk
>>> shape = (4, 4)
>>> img = np.zeros(shape, dtype=np.uint8)
>>> rr, cc = disk((0, 0), 2, shape=shape)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 0, 0],
       [1, 1, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=uint8)
>>> img = np.zeros(shape, dtype=np.uint8)
>>> # Negative coordinates in rr and cc perform a wraparound
>>> rr, cc = disk((0, 0), 2, shape=None)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 0, 1],
       [1, 1, 0, 1],
       [0, 0, 0, 0],
       [1, 1, 0, 1]], dtype=uint8)
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = disk((4, 4), 5)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

相關用法


注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.draw.disk。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。