我是影像處理的初學者。
我使用 RGB 影像image.shape = (4512,3000,3)
我看到了第一個像素的值:image[0][0] = [210 213 220]
當我使用該rgb2gray功能時,結果是rgb2gray(image[0][0]) = 0.8347733333333334
但我看到該函式使用的關系是Y = 0.2125 * R 0.7454 * G 0.0721 * B. 我做了計算,我應該有Y = im[0,0,0] * 0.2125 im[0,0,1] * 0.7154 im[0,0,2] * 0.0721 = 212.8672
看來我的結果是212.8672/255 = 0.8347733333333334
為什么結果在 0 和 1 之間,而不是在 0 和 255 之間?
uj5u.com熱心網友回復:
我假設您使用的是 scikit-image 的 rgb2gray。在這種情況下,您可以在https://github.com/scikit-image/scikit-image/blob/main/skimage/color/colorconv.py的代碼中看到顏色模塊中的每個顏色轉換都以_prepare_colorarray方法開始它轉換為浮點表示。
def _prepare_colorarray(arr, force_copy=False, *, channel_axis=-1):
"""Check the shape of the array and convert it to
floating point representation.
"""
arr = np.asanyarray(arr)
if arr.shape[channel_axis] != 3:
msg = (f'the input array must have size 3 along `channel_axis`, '
f'got {arr.shape}')
raise ValueError(msg)
float_dtype = _supported_float_type(arr.dtype)
if float_dtype == np.float32:
_func = dtype.img_as_float32
else:
_func = dtype.img_as_float64
return _func(arr, force_copy=force_copy)
該模塊確實(謝天謝地)支持 8 位 int 表示作為輸入,但將影像陣列轉換為浮點表示并一直使用該表示。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424384.html
上一篇:如何裁剪已經調整大小的視頻流?
