繁体   English   中英

跨颜色通道的归一化

[英]Normalization across colour channels in numpy

我有一个(10000、32、32、3)的numpy数组(10000张图像,32像素乘32像素,3个颜色通道),并尝试分别对最后三个通道中的每一个进行规范化。

为了规范化我尝试使用的红色通道

testX[:,:,:,0] = (testX[:,:,:,0]-np.mean(testX[:,:,:,0]))/np.std(testX[:,:,:,0])

而不是沿着红色列生成标准化输出,例如:(这是其中一张图像的最后一行像素)

[[
      ...,
    [[-1.78, 108,  94],
     [ 0.54,  37,  21],
     [ 0.12, 136, 127],
     ..., 
     [-0.68, 172, 114],
     [ 0.97, 204, 141],
     [ 1.20, 182, 118]]]]

它将所有红色单元格设置为0、1或255

[[
     ...,
    [[  0, 108,  94],
     [255,  37,  21],
     [  0, 136, 127],
     ..., 
     [  0, 172, 114],
     [  0, 204, 141],
     [  1, 182, 118]]]]

我对切片功能缺少什么?

有没有更好的方法可以做到这一点?

由于我正在尝试对此进行归一化,所以做一些简单得多的事情而不是去烦恼颜色归一化会更有意义吗?

testX = testX/255

我想知道这是否可能是由于将最终numpy数组的数据类型设置为int而不是float引起的。 请参见以下示例,其中“ x”是图像数据:

redchannel = x[:,:,:,0]   
greenchannel = x[:,:,:,1]
bluechannel = x[:,:,:,2]
a = 0.0
b = 1.0
imgdata_min = 0
imgdata_max = 255

normalized_redchannel = a + ((( redchannel - imgdata_min)*(b - a))/(imgdata_max - imgdata_min))

# merge channels
x_with_normalized_red = np.stack((normalized_redchannel,greenchannel,bluechannel), axis=3)
print(x_with_normalized_red.astype('int32')) # prints 0/1 values
print(x_with_normalized_red.astype('float32')) # prints floating point values

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM