图片数组之间的关系,还有python相关库的总结

首先是opencv库:

import cv2
cv2.imread(path)

要注意的是,cv2默认读取图片为三通道,若本来为单通道或RGBA,还是width×height×3
要想根据具体情况读取,则有:

cv2.imread(path ,cv2.IMREAD_COLOR)  # 默认
cv2.imread(path ,cv2.IMREAD_GRAYSCALE)  # 单通道

之后有PIL库 Image:

import PIL.Image as Image
img = Image.open(path)
print(img.mode, img.format, img.size)

可查看图片相关信息。

还有numpy库:

import numpy as np
imgnp = np.ndarray((512, 512, 3), dtype=np.uint8)  # 随机,512×512 RGB
img0 = np.zeros((512, 512, 3), dtype=np.uint8)  # 全0 黑图
np.arange(12).reshape(3,4) :
            [[ 0  1  2  3]
             [ 4  5  6  7]
             [ 8  9 10 11]]
np.arange(12).reshape(-1,6):
            [[ 0  1  2  3  4  5]
             [ 6  7  8  9 10 11]]
np.arange(12).reshape(6,-1):
            [[ 0  1]
             [ 2  3]
             [ 4  5]
             [ 6  7]
             [ 8  9]
             [10 11]]

reshape若有参数为-1,则表示该维度数据数目不知道,根据其他维度得来

keras中有ImageDataGenerator, array_to_img, img_to_array, load_img库:

from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

和opencv功能类似

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值