我正在使用MNIST数据集,它包含数字的黑白图像。我正在尝试将数字(白色部分)从白色/灰色更改为与白色相同程度的不同颜色,例如红色。我使用opencv将它们转换为rgb图像,而不是灰度图像,并将它们打包成如下数组:
cImgsTrain = np.asarray([cv2.cvtColor(img.reshape(28,28),cv2.COLOR_GRAY2RGB) for img in x_train])
及
cImgsTrain.shape
输出
(60000, 28, 28, 3)
60000张图像,每幅28x28,三个rgb通道
我将如何更改其中的第一幅图像cImgsTrain[0]
,从这个白色版本变为红色版本,并使白色像素变为深红色,灰色像素变为浅色调?是否有一个功能可以帮助实现这一点
由于您希望以与先前的白色/灰色相同的强度更改为红色,为什么不将两个空白图像叠加在一起呢
OpenCV使用BGR,所以我将使用它而不是RGB,但如果需要RGB,您可以更改它
您可以使用此代码并查看。它应该会起作用
您可以使用当前灰度输入作为红色通道,并将所有绿色和蓝色通道设置为零。您可以将其切换为蓝色或绿色
相关问题 更多 >
编程相关推荐