文章目录
一、图片读取
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
imagePath = r'./test.png'
img = Image.open(imagePath).convert('RGB')
plt.imshow(img)
plt.show()
图片显示:
二、均值和标准差计算
img = img.getdata()
img = np.array(img)
print(img.shape)
print(img.mean(axis=0), '====', img.std(axis=0))
结果输出:
(90000, 3) # img.shape = (w*h, c)
[125.85675556 98.85408889 112.46821111] ==== [58.50427632 43.50618703 50.75970898]