图像属性shape,size,dtype

import cv2
if __name__=='__main__':
    src = "./samples/cat_dog.png"
    image = cv2.imread(src)
    GrayImage = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

    #图像形状-shape返回行数,列数,通道数(如果是灰度图像,最后的通道数为一且不显示)
    print(image.shape)
    print(GrayImage.shape)


    #图像大小-size返回图像的像素数目行数*列数*通道数
    print(image.size)
    print(GrayImage.size)

    #图像类型-dtype返回图像的的,通常返回uint8
    print(image.dtype)
    print(GrayImage.dtype)

(224, 224, 3)   长 宽 通道数
(224, 224) 
150528    长*宽*通道数
50176
uint8
uint8

import numpy as np
a = np.array([1,2,3,4,5,6,7,8])  #一维数组
print(a.shape[0])  #值为8,因为有8个数据
print(a.shape[1])  #IndexError: tuple index out of range

a = np.array([[1,2,3,4],[5,6,7,8]])  #二维数组
print(a.shape[0])  #值为2,最外层矩阵有2个元素,2个元素还是矩阵。
print(a.shape[1])  #值为4,内层矩阵有4个元素。
print(a.shape[2])  #IndexError: tuple index out of range

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值