我想了解什么是keras.preprocessing.image.img_to_array
?
当我查看数组的内容时,它们如下(所有元素都在float中):
image1 = img_to_array(image.load_img(ImagePath, target_size=(128,128))) / 255
[0.16470588743686676, 0.3019607961177826, 0.07450980693101883], [0.1we23423423486676, 0.3023423423423423, 0.01353463453458483] ......
它们似乎是图像的RGB通道,但为什么它是分数?但是,如果我在C#中查看位图,它们是整数,如(Alpha,R,G,B)
[100,123,024,132],[021,055,243,015]....
有人可以解释一下从C#中的img_to_array和Bitmap数组格式生成的图像数组的区别是什么?
谢谢,PCG
img_to_array
在Keras implementation的文档中得到了很好的解释:
def img_to_array(img, data_format='channels_last', dtype='float32'):
"""Converts a PIL Image instance to a Numpy array.
# Arguments
img: PIL Image instance.
data_format: Image data format,
either "channels_first" or "channels_last".
dtype: Dtype to use for the returned array.
# Returns
A 3D Numpy array.
# Raises
ValueError: if invalid `img` or `data_format` is passed.
"""
所以它将采用PIL Image实例并将其转换为numpy数组,使用dtype float32。如果从PNG图像开始,图像内的值将介于0和255之间。这通常由8位无符号整数表示;然而,img_to_array
将被抛弃。在您的代码示例中,数组除以255,这就是为什么您最终得到0到1之间的浮点数。