代码之家  ›  专栏  ›  技术社区  ›  Shan Khan

是否可以为RGB和灰度图像创建训练矩阵

  •  -1
  • Shan Khan  · 技术社区  · 6 年前

    我正在为CNN创建培训矩阵。 图像既有RGB又有灰度。

    创造出 [ # of images, #features ]

    图像大小为:

    1024* 1024

    以下是我的代码:

    from skimage.transform import rescale, resize
    from skimage import io
    
    features = np.empty((0,1024 * 1024), np.float32)
    imagePath = directoyPath+"/"+ imageName
    image = io.imread(imagePath)
    print(image.shape)
    flatFeatures = np.reshape(image,(1,1024*1024))
    print(flatFeatures.shape)
    features = np.append(features, flatFeatures, axis=0)
    print(features.shape)
    

    问题是RGB的形状是(10241024,3)。

    如何将RGB和灰度图像传送到 features 矩阵。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Imtinan Azhar    6 年前

    简单地说,在将RGB图像转换为灰度图像后,您将无法将不同频道的图像传送到CNN,因为RGB有3个频道,灰度图像有1个频道,在CNN的输入层指定频道是必要的,它不能是动态的,因此您必须确保您有3个频道或一

    出于您的目的,我建议您使用 cvtColor(gray, color, cv::COLOR_GRAY2BGR) 图像实际上不会获得任何颜色,但其中的通道数为3,允许您同时传递RGB和灰度(技术上是RGB,但仍然无色)图像。