简体   繁体   English

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

[英]Is there possible to create training matrix for both RGB and Gray Scale images

I'm trying to create training matrix for CNN.我正在尝试为 CNN 创建训练矩阵。 Images are both RGB and Grey/scale.图像是 RGB 和灰度/比例。

To create something like [ # of images, #features ]要创建类似[ # of images, #features ]

Image Size is :图像大小为:

1024* 1024

Following is my code:以下是我的代码:

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)

The problem is RGB shape is (1024,1024,3).问题是 RGB 形状是 (1024,1024,3)。

How i can feed the RGB and grey scale images to features matrix.我如何将 RGB 和灰度图像提供给features矩阵。

simply you would have to feed in the RGB images after converting it into greyscale, you cannot pass images of different channels into a CNN, since RGB have 3 channels and grey scale images have 1 channel, specifying channels in the input layer of a CNN are necessary, it cannot be dynamic, so you have to make sure that you either have 3 channels or 1简单地说,您必须在将其转换为灰度后输入 RGB 图像,您不能将不同通道的图像传递到 CNN,因为 RGB 有 3 个通道,灰度图像有 1 个通道,在 CNN 的输入层中指定通道是必要的,它不能是动态的,所以你必须确保你有 3 个通道或 1 个

for your purposes i would suggest you convert your grayscale images to RGB using cvtColor(gray, color, cv::COLOR_GRAY2BGR) the image wouldn't actually gain any color, but the number of channels in it would be 3, allowing you to pass both RGB and grayscale(technically RGB but still colorless) images together出于您的目的,我建议您使用cvtColor(gray, color, cv::COLOR_GRAY2BGR)将灰度图像转换为 RGB 图像实际上不会获得任何颜色,但其中的通道数为 3,允许您通过RGB 和灰度(技术上为 RGB 但仍然无色)图像在一起

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

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