用法:
skimage.util.invert(image, signed_float=False)
反轉圖像。
反轉輸入圖像的強度範圍,使 dtype 最大值現在是 dtype 最小值,反之亦然。此操作根據輸入 dtype 略有不同:
- 無符號整數:從 dtype 最大值中減去圖像
- 有符號整數:從 -1 中減去圖像(見注釋)
- 浮點數:從 1 中減去圖像(如果 signed_float 為 False,因此我們假設圖像是無符號的),或從 0 中減去(如果 signed_float 為 True)。
請參閱示例以進行說明。
- image:ndarray
輸入圖像。
- signed_float:布爾型,可選
如果為 True 並且圖像是浮點類型,則假定範圍為 [-1, 1]。如果 False 並且圖像是浮點類型,則假定範圍為 [0, 1]。
- inverted:ndarray
倒象。
參數:
返回:
注意:
理想情況下,對於有符號整數,我們隻需乘以 -1。但是,有符號整數範圍是不對稱的。例如,對於 np.int8,可能值的範圍是 [-128, 127],因此 -128 * -1 等於 -128!通過從 -1 中減去,我們正確地將最大 dtype 值映射到最小值。
例子:
>>> img = np.array([[100, 0, 200], ... [ 0, 50, 0], ... [ 30, 0, 255]], np.uint8) >>> invert(img) array([[155, 255, 55], [255, 205, 255], [225, 255, 0]], dtype=uint8) >>> img2 = np.array([[ -2, 0, -128], ... [127, 0, 5]], np.int8) >>> invert(img2) array([[ 1, -1, 127], [-128, -1, -6]], dtype=int8) >>> img3 = np.array([[ 0., 1., 0.5, 0.75]]) >>> invert(img3) array([[1. , 0. , 0.5 , 0.25]]) >>> img4 = np.array([[ 0., 1., -1., -0.25]]) >>> invert(img4, signed_float=True) array([[-0. , -1. , 1. , 0.25]])
相關用法
- Python skimage.util.view_as_windows用法及代碼示例
- Python skimage.util.montage用法及代碼示例
- Python skimage.util.regular_grid用法及代碼示例
- Python skimage.util.label_points用法及代碼示例
- Python skimage.util.regular_seeds用法及代碼示例
- Python skimage.util.view_as_blocks用法及代碼示例
- Python skimage.util.unique_rows用法及代碼示例
- Python skimage.feature.graycomatrix用法及代碼示例
- Python skimage.color.lab2lch用法及代碼示例
- Python skimage.draw.random_shapes用法及代碼示例
- Python skimage.feature.blob_doh用法及代碼示例
- Python skimage.feature.blob_dog用法及代碼示例
- Python skimage.filters.unsharp_mask用法及代碼示例
- Python skimage.registration.optical_flow_tvl1用法及代碼示例
- Python skimage.filters.rank.noise_filter用法及代碼示例
- Python skimage.exposure.histogram用法及代碼示例
- Python skimage.filters.gaussian用法及代碼示例
- Python skimage.feature.graycoprops用法及代碼示例
- Python skimage.segmentation.active_contour用法及代碼示例
- Python skimage.feature.corner_orientations用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.util.invert。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。