绘制图片直方图
import numpy as np from PIL import Image from matplotlib import pyplot as plt img=np.array(Image.open(./img/lena.png).convert(L)) plt.figure("lena") arr=img.flatten() n, bins, patches = plt.hist(arr, bins=256, density=1, facecolor='blue', alpha=0.75) plt.show()
效果如下