繁体   English   中英

Scikit图片中的RGB至XYZ

[英]RGB to XYZ in Scikit-Image

我正在尝试使用scikit-image将图像从RGB转换为XYZ。 我发现根据输入类型存在一些差异:

from numpy import array,uint8
import skimage.color

rgb = array([array([[56,79,132],[255,100,70]])]) 
i1 = skimage.color.rgb2xyz(rgb)#rgb.dtype ->dtype('int32')
i2 = skimage.color.rgb2xyz(rgb.astype(uint8))
i3 = skimage.color.rgb2xyz(rgb.astype(float))

print i1[0,1,:]
print i2[0,1,:]
print i3[0,1,:]

这是输出:

[  5.55183419e-09   4.73226247e-09   3.02426596e-09]
[ 0.46907236  0.3082294   0.09272133]
[ 240644.54537677  153080.21825017   39214.47581034]

导致差异的原因是在img_to_float内部使用的函数rgb2xyz (请参见此问题 )。

但是我想知道:使用rgb2xyz的正确方法是什么?

关于此问题 ,有多种解决方案,具体取决于公式,但同样: rgb2xyz 要求的正确图像类型是什么? 似乎是unit8 ,但是为什么呢? 谢谢!

以下代码应具有自解释性,但浮点值的范围应在(0, 1) ,整数类型的完整范围应映射到(0, 1) (对于无符号类型)或(-1, 1) (对于带符号的类型):

>>> from numpy import int32
>>> skimage.color.rgb2xyz((rgb / 255 * (2**31 - 1)).astype(int32))
array([[[ 0.08590003,  0.08097913,  0.2293394 ],
        [ 0.46907236,  0.3082294 ,  0.09272133]]])
>>> skimage.color.rgb2xyz(rgb.astype(uint8))
array([[[ 0.08590003,  0.08097913,  0.2293394 ],
        [ 0.46907236,  0.3082294 ,  0.09272133]]])
>>> skimage.color.rgb2xyz(rgb.astype(float) / 255)
array([[[ 0.08590003,  0.08097913,  0.2293394 ],
        [ 0.46907236,  0.3082294 ,  0.09272133]]])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM