用法:
skimage.draw.rectangle(start, end=None, extent=None, shape=None)
生成矩形內像素的坐標。
- start:元組
矩形的原點,例如
([plane,] row, column)
。- end:元組
矩形的終點
([plane,] row, column)
.對於二維矩陣,矩形定義的切片為[start:(end+1)]
.任何一個結尾或者程度必須指定。- extent:元組
繪製矩形的範圍(大小)。例如:,
([num_planes,] num_rows, num_cols)
.任何一個結尾或者程度必須指定。負範圍是有效的,並且會產生一個沿相反方向的矩形。如果範圍為負,則開始點不包括在內。- shape:元組,可選
用於確定輸出坐標的最大邊界的圖像形狀。這對於裁剪超出圖像大小的矩形很有用。默認情況下,不進行剪輯。
- coords:int 形狀數組(Ndim,Npoints)
矩形中所有像素的坐標。
參數:
返回:
注意:
通過將 start 和 end 或 extent 作為長度為 N 的元組傳遞,此函數可以應用於 N 維圖像。
例子:
>>> import numpy as np >>> from skimage.draw import rectangle >>> img = np.zeros((5, 5), dtype=np.uint8) >>> start = (1, 1) >>> extent = (3, 3) >>> rr, cc = rectangle(start, extent=extent, shape=img.shape) >>> img[rr, cc] = 1 >>> img array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]], dtype=uint8)
>>> img = np.zeros((5, 5), dtype=np.uint8) >>> start = (0, 1) >>> end = (3, 3) >>> rr, cc = rectangle(start, end=end, shape=img.shape) >>> img[rr, cc] = 1 >>> img array([[0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]], dtype=uint8)
>>> import numpy as np >>> from skimage.draw import rectangle >>> img = np.zeros((6, 6), dtype=np.uint8) >>> start = (3, 3) >>> >>> rr, cc = rectangle(start, extent=(2, 2)) >>> img[rr, cc] = 1 >>> rr, cc = rectangle(start, extent=(-2, 2)) >>> img[rr, cc] = 2 >>> rr, cc = rectangle(start, extent=(-2, -2)) >>> img[rr, cc] = 3 >>> rr, cc = rectangle(start, extent=(2, -2)) >>> img[rr, cc] = 4 >>> print(img) [[0 0 0 0 0 0] [0 3 3 2 2 0] [0 3 3 2 2 0] [0 4 4 1 1 0] [0 4 4 1 1 0] [0 0 0 0 0 0]]
相關用法
- Python skimage.draw.rectangle_perimeter用法及代碼示例
- Python skimage.draw.random_shapes用法及代碼示例
- Python skimage.draw.polygon2mask用法及代碼示例
- Python skimage.draw.ellipse_perimeter用法及代碼示例
- Python skimage.draw.bezier_curve用法及代碼示例
- Python skimage.draw.line用法及代碼示例
- Python skimage.draw.set_color用法及代碼示例
- Python skimage.draw.circle_perimeter用法及代碼示例
- Python skimage.draw.polygon用法及代碼示例
- Python skimage.draw.ellipse用法及代碼示例
- Python skimage.draw.polygon_perimeter用法及代碼示例
- Python skimage.draw.circle_perimeter_aa用法及代碼示例
- Python skimage.draw.line_nd用法及代碼示例
- Python skimage.draw.disk用法及代碼示例
- Python skimage.draw.line_aa用法及代碼示例
- Python skimage.data.binary_blobs用法及代碼示例
- Python skimage.data.file_hash用法及代碼示例
- Python skimage.feature.graycomatrix用法及代碼示例
- Python skimage.color.lab2lch用法及代碼示例
- Python skimage.feature.blob_doh用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.draw.rectangle。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。