用法:
skimage.exposure.rescale_intensity(image, in_range='image', out_range='dtype')
拉伸或縮小其強度級別後返回圖像。
輸入和輸出所需的強度範圍,分別為in_range和out_range,用於拉伸或縮小輸入圖像的強度範圍。請參閱下麵的示例。
- image:數組
圖像陣列。
- in_range, out_range:str 或 2 元組,可選
輸入和輸出圖像的最小和最大強度值。下麵列舉了該參數的可能值。
- ‘image’
使用圖像最小/最大作為強度範圍。
- ‘dtype’
使用圖像 dtype 的 min/max 作為強度範圍。
- dtype-name
根據所需的 dtype 使用強度範圍。必須是DTYPE_RANGE 中的有效 key 。
- 2元組
使用range_values 作為明確的最小/最大強度。
- out:數組
重新調整其強度後的圖像陣列。此圖像與輸入圖像具有相同的 dtype。
參數:
返回:
注意:
例子:
默認情況下,輸入圖像的最小/最大強度被拉伸到圖像 dtype 允許的限製,因為 in_range 默認為 ‘image’ 而 out_range 默認為 ‘dtype’:
>>> image = np.array([51, 102, 153], dtype=np.uint8) >>> rescale_intensity(image) array([ 0, 127, 255], dtype=uint8)
很容易意外地將圖像 dtype 從 uint8 轉換為 float:
>>> 1.0 * image array([ 51., 102., 153.])
使用
rescale_intensity
>>> image_float = 1.0 * image >>> rescale_intensity(image_float) array([0. , 0.5, 1. ])
要保持原件的低對比度,請使用 in_range 參數:
>>> rescale_intensity(image_float, in_range=(0, 255)) array([0.2, 0.4, 0.6])
如果in_range 的最小/最大值大於/小於最小/最大圖像強度,則剪切強度級別:
>>> rescale_intensity(image_float, in_range=(0, 102)) array([0.5, 1. , 1. ])
如果您有一個帶符號整數的圖像,但想要將圖像重新縮放到正範圍,請使用 out_range 參數。在這種情況下,輸出 dtype 將是浮點數:
>>> image = np.array([-10, 0, 10], dtype=np.int8) >>> rescale_intensity(image, out_range=(0, 127)) array([ 0. , 63.5, 127. ])
要獲得具有特定 dtype 的所需範圍,請使用
.astype()
:>>> rescale_intensity(image, out_range=(0, 127)).astype(np.int8) array([ 0, 63, 127], dtype=int8)
如果輸入圖像是常量,輸出會直接裁剪到輸出範圍:>>> image = np.array([130, 130, 130], dtype=np.int32) >>> rescale_intensity(image, out_range=(0, 127)).astype(np.int32) 數組([127, 127, 127], dtype=int32)
相關用法
- Python skimage.exposure.histogram用法及代碼示例
- Python skimage.exposure.adjust_gamma用法及代碼示例
- Python skimage.exposure.is_low_contrast用法及代碼示例
- Python skimage.exposure.cumulative_distribution用法及代碼示例
- 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.filters.gaussian用法及代碼示例
- Python skimage.feature.graycoprops用法及代碼示例
- Python skimage.segmentation.active_contour用法及代碼示例
- Python skimage.feature.corner_orientations用法及代碼示例
- Python skimage.morphology.h_minima用法及代碼示例
- Python skimage.filters.threshold_otsu用法及代碼示例
- Python skimage.feature.structure_tensor用法及代碼示例
- Python skimage.transform.hough_circle_peaks用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.exposure.rescale_intensity。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。