2

【计算机视觉】OpenCV 4高级编程与项目实战(Python版)【6】:使用NumPy创建随机雪花...

 1 year ago
source link: https://blog.csdn.net/nokiaguy/article/details/129250204
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

上一篇文章演示了如何使用二维数组创建黑白图像,如果要创建彩色图像,就需要使用三维数组。例如,在BGR色彩空间创建200 × 200的彩色图像,就需要一个200 ×200 ×3的三维数组存储像素的颜色值,其中第3维可以存储3个通道的颜色值,分别是B通道、G通道和R通道。也就是我们平常说的三原色:蓝(B)、绿(G)和红(R)。

  1. 创建彩色图像

下面的代码,创建一个三维数组,数组元素初始值都是0,然后将该数组复制3份,将第1个数组的通道1(B通道)设置为255,将第2个数组的通道2(G通道)设置为255,将第3个数组的通道3(R通道)设置为255,这将形成3幅纯色的图像。代码如下:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK