我得到了一个图像(32,32,3)和两个表示均值和标准差的向量(3,)。我试图通过使图像进入可以减去平均值并除以std的状态来归一化图像,但当我试图绘制它时,我得到了以下错误。
ValueError: Floating point image RGB values must be in the 0..1 range.我理解这个错误,所以我认为当我试图规范化时,我没有执行正确的操作。下面是我试着用来规格化图像的代码。
mean.shape #(3,)
std.shape #(3,)
sample.shape #(32,32,3)
# trying to unroll and by RGB channels
channel_1 = sample[:, :, 0].ravel()
channel_2 = sample[:, :, 1].ravel()
channel_3 = sample[:, :, 2].ravel()
# Putting the vectors together so I can try to normalize
rbg_matrix = np.column_stack((channel_1,channel_2,channel_3))
# Trying to normalize
rbg_matrix = rbg_matrix - mean
rbg_matrix = rbg_matrix / std
# Trying to put back in "image" form
rgb_image = np.reshape(rbg_matrix,(32,32,3))发布于 2018-03-22 21:22:53
您的错误似乎指向图像缺乏规范化。
我已经使用此函数对我的Deep Learning项目中的图像进行了标准化
def normalize(x):
"""
Normalize a list of sample image data in the range of 0 to 1
: x: List of image data. The image shape is (32, 32, 3)
: return: Numpy array of normalized data
"""
return np.array((x - np.min(x)) / (np.max(x) - np.min(x)))https://stackoverflow.com/questions/49429734
复制相似问题