我得到了一个图像(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)))发布于 2018-03-23 03:39:45
通过将图像的平均值设置为0并将其标准差设置为1来归一化图像,就像您所做的那样,导致图像中的大多数(但不是所有)像素都在-2,2的范围内。这对于进一步的处理非常有效,并且通常显式地应用于某些机器学习方法中。我见过它被称为“美白”,但更恰当的叫法是standardization transform。
您使用的绘图函数似乎希望图像在0,1的范围内。这是绘图函数的限制,而不是归一化的限制。Other image display functions将能够完美地显示您的图像。
要规格化到0,1范围,不应使用平均值和标准差,而应使用最大值和最小值,如Pitto's answer中所示。
https://stackoverflow.com/questions/49429734
复制相似问题