ほとんど自分用ですが、第一引数に入力画像の名前を、第二引数に出力する画像の名前を渡すとその画像をヒストグラム解析したものが出てくる関数を作成しました。
import cv2
import numpy as np
import matplotlib.pyplot as plt
def get_imghist(img_name,output_name):
fig = plt.figure()
img = cv2.imread(f"{img_name}")
dst = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_histogram, img_bins = np.histogram(np.array(dst).flatten(), bins=np.arange(256+1))
plt.plot(img_histogram)
fig.savefig(str(output_name),dpi=500)