一、图像结构
1.概念
python有数据类型的概念,但不同于其他语言,在定义图像的时候,可以不用声明数据类型。
2.图像存储结构
图像在计算机中是通过像素矩阵的结构形式存储。
3.图像颜色空间
颜料三原色:品红、黄、青(天蓝)
光学三原色: 红、绿、蓝(靛蓝)
计算机中采用光学三原色(BGR)存储像素值[0~255]。
(255, 0, 0) # 蓝色 b
(0, 255, 0) # 绿色 g
(0, 0, 255) # 红色 r
(0, 0, 0) # 黑色
(255, 255, 255) # 白色
二、图像属性
1.属性
opencv-python提供两种访问图像尺寸的方式shape和size:
(1)shape:三元组,包括图像的行(rows)、列(cols)、深度(depth);
(2)size:size = rows × cols × depth;
img.shape
img.size
img.dtype # 图像的类型
2.代码示例
img = cv.imread('./images/me.jpg')
print(img.dtype)
print(img.size) # size = rows*cols*depth
print(img.shape)
print(img.shape[0]) # 行 rows
print(img.shape[1]) # 列 cols
print(img.shape[2]) # 深度 depth
输出结果:
三、图像坐标
1、坐标与行列
图像左上角的坐标为(0,0)
横坐标对应列,纵坐标对应行。
图像的中点坐标为:
print("图像的中点坐标为:(", img.shape[1]/2, ", ", img.shape[0]/2, ")")