我正在尝试Skimge的color.rgb2gray函数。结果数组应根据功能说明进行归一化。

但是我发现在某些情况下最大值不是1

例如:

[In]:color.rgb2gray(data.chelsea()).max()
[out]:0.7556109803921569
[In]:color.rgb2gray(data.coins()).max()
[out]:252


有人对此有想法吗?

最佳答案

我没有看到文档字符串说出任何有关规范化的内容。但是,您遇到的问题是skimage可以同时理解用dtype == np.uint8dtype == float表示的图像。后面的图像在[0,1]中,前面的图像在[0,255]中。因此,您将看到:

In [7]: color.rgb2gray(data.chelsea()).max()
Out[7]: 0.75561098039215691

In [8]: color.rgb2gray(data.chelsea()).dtype
Out[8]: dtype('float64')

In [9]: color.rgb2gray(data.coins()).max()
Out[9]: 252

In [10]: color.rgb2gray(data.coins()).dtype
Out[10]: dtype('uint8')


另见http://scikit-image.org/docs/0.14.x/user_guide/data_types.html

10-04 22:15
查看更多