认识numpy
1、导入numpy,matplotlib.pyplot模块,并将其别名
import numpy as np
import matplotlib.pyplot as plt
2、读取图片 :imge = plt.imread(‘logo.jpg’)
# 输出结果:
array([[[231, 186, 131],
[232, 187, 132],
[233, 188, 133],
...,
[100, 54, 54],
[ 92, 48, 47],
[ 85, 43, 44]],
[[232, 187, 132],
[232, 187, 132],
[233, 188, 133],
...,
[100, 54, 54],
[ 92, 48, 47],
[ 84, 42, 43]],
[[232, 187, 132],
[233, 188, 133],
[233, 188, 133],
...,
[ 99, 53, 53],
[ 91, 47, 46],
[ 83, 41, 42]],
...,
[[199, 119, 82],
[199, 119, 82],
[200, 120, 83],
...,
[189, 99, 65],
[187, 97, 63],
[187, 97, 63]],
[[199, 119, 82],
[199, 119, 82],
[199, 119, 82],
...,
[188, 98, 64],
[186, 96, 62],
[188, 95, 62]],
[[199, 119, 82],
[199, 119, 82],
[199, 119, 82],
...,
[188, 98, 64],
[188, 95, 62],
[188, 95, 62]]], dtype=uint8)
3、显示图片:plt.imshow(imge)
4、读取矩阵长度:image.shape
# 输出结果
(920, 1080, 3)
5、随机生成图片并显示
img = np.random.randint(0,255,size=(456,730,3))
img = im.astype(np.float64)
plt.imshow(img)
# 输出结果如下