首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试标准化Python图像时出现错误- RGB值必须在0..1范围内

尝试标准化Python图像时出现错误- RGB值必须在0..1范围内
EN

Stack Overflow用户
提问于 2018-03-22 21:17:31
回答 2查看 3.7K关注 0票数 2

我得到了一个图像(32,32,3)和两个表示均值和标准差的向量(3,)。我试图通过使图像进入可以减去平均值并除以std的状态来归一化图像,但当我试图绘制它时,我得到了以下错误。

代码语言:javascript
复制
ValueError: Floating point image RGB values must be in the 0..1 range.

我理解这个错误,所以我认为当我试图规范化时,我没有执行正确的操作。下面是我试着用来规格化图像的代码。

代码语言:javascript
复制
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))
EN

Stack Overflow用户

发布于 2018-03-22 21:22:53

您的错误似乎指向图像缺乏规范化。

我已经使用此函数对我的Deep Learning项目中的图像进行了标准化

代码语言:javascript
复制
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)))
票数 6
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49429734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档