运营推广计划表,网站优化提升速度,wordpress博客好用吗,江苏网站设计公司电话专栏地址#xff1a;『youcans 的 OpenCV 例程 300 篇』 【OpenCV 例程300篇】05. 图像的属性#xff08;np.shape#xff09; OpenCV 中图像对象的数据结构是 ndarray 多维数组#xff0c;因此 ndarray 数组的属性和操作方法也都适用于 OpenCV 的图像对象。 img.ndim…专栏地址『youcans 的 OpenCV 例程 300 篇』 【OpenCV 例程300篇】05. 图像的属性np.shape OpenCV 中图像对象的数据结构是 ndarray 多维数组因此 ndarray 数组的属性和操作方法也都适用于 OpenCV 的图像对象。 img.ndim查看图像的维数彩色图像的维数为 3灰度图像的维数为 2。img.shape查看图像的形状即图像栅格的行数高度、列数宽度、通道数。img.size查看图像数组元素总数灰度图像的数组元素总数为像素数量彩色图像的数组元素总数为像素数量与通道数的乘积。
基本例程 # 1.11 图像数组的属性imgFile ../images/imgLena.tif # 读取文件的路径img1 cv2.imread(imgFile, flags1) # flags1 读取彩色图像(BGR)img2 cv2.imread(imgFile, flags0) # flags0 读取为灰度图像# cv2.imshow(Demo1, img1) # 在窗口显示图像# key cv2.waitKey(0) # 等待按键命令# 维数(ndim), 形状(shape), 元素总数(size), 元素类型(dtype)print(Ndim of img1(BGR): {}, img2(Gray): {}.format(img1.ndim, img2.ndim)) # number of rows, columns and channelsprint(Shape of img1(BGR): {}, img2(Gray): {}.format(img1.shape, img2.shape)) # number of rows, columns and channelsprint(Size of img1(BGR): {}, img2(Gray): {}.format(img1.size, img2.size)) # size rows * columns * channelsprint(Dtype of img1(BGR): {}, img2(Gray): {}.format(img1.dtype, img2.dtype)) # uint8本例程的运行结果如下
Ndim of img1(BGR): 3, img2(Gray): 2
Shape of img1(BGR): (512, 512, 3), img2(Gray): (512, 512)
Size of img1(BGR): 786432, img2(Gray): 262144
Dtype of img1(BGR): uint8, img2(Gray): uint8通过资源管理器查看彩色图像和灰度图像的属性如下图彩色图像的位深度为 24灰度图像的位深度为 8。 本节完 【第1章图像的基本操作】 01. 图像的读取cv2.imread 02. 图像的保存cv2.imwrite 03. 图像的显示cv2.imshow 04. 用 matplotlib 显示图像plt.imshow 05. 图像的属性np.shape 版权声明 youcansxupt 原创作品转载必须标注原文链接(https://blog.csdn.net/youcans/article/details/125112487) Copyright 2022 youcans, XUPT Crated2021-11-18