如何获得numpy.zeros数()和(小家伙()*255)分别生成黑白图像?

2024-04-27 00:13:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python+OpenCV的新手,所以这对大多数人来说可能是一个基本问题,因为我在网上找不到一个好的/令人满意的解决方案。你知道吗

因此,我尝试通过分别创建R-G-B层来创建图像
R-0s层
G-255s层
255*单位矩阵的B层

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

Red = np.zeros([6, 6], dtype = np.uint8)
plt.imshow(Red)        # it is just the red layer which is actually all black
plt.show()

Green = np.ones([6, 6], dtype = np.uint8) * 255
plt.imshow(Green)      # it is just the Green layer which is actually all white
plt.show()

Blue = np.eye(6, dtype = int) * 255
plt.imshow(Blue)       # it is just the Blue layer which is actually black with white diag
plt.show()

但实际上我得到的是紫色或者紫色和黄色的组合。 My Output

有人能解释发生了什么和/或如何解决吗?你知道吗


Tags: theimportlayerwhichisasshownp