2 回答

TA貢獻1801條經驗 獲得超8個贊
由于您想以與之前的白色/灰色相同的強度更改為紅色,為什么不將兩個空白圖像與其一起堆疊。
OpenCV 使用 BGR,所以我將使用 BGR 而不是 RGB,但如果需要 RGB,您可以更改它。
import numpy as np
#assuming img contains a grayscale image of size 28x28
b = np.zeros((28, 28), dtype=np.uint8)
g = np.zeros((28, 28), dtype=np.uint8)
res = cv2.merge((b, g, img))
cv2.imshow('Result', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
您可以使用此代碼并查看。它應該工作。

TA貢獻1829條經驗 獲得超7個贊
您可以將當前的灰度輸入用作紅色通道,并將所有綠色和藍色通道設置為零。您可以切換它們以使數字具有藍色或綠色。
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
(x, _), (_, _) = tf.keras.datasets.mnist.load_data()
x = x[0]
f = np.concatenate([x[..., None],
np.zeros((28, 28, 1)).astype(int),
np.zeros((28, 28, 1)).astype(int)], axis=-1)
plt.imshow(f)
添加回答
舉報