import cv2
import numpy as np
import matplotlib.pyplot as plt

image = cv2.imread("../data/2.jpg", 0)

mask = np.zeros(image.shape, np.uint8)
mask[200:400, 200:400] = 255  # 制作掩膜

histImage = cv2.calcHist([image], [0], None, [256], [0, 255])
mask_histImage = cv2.calcHist([image], [0], mask, [256], [0, 255])

plt.plot(histImage)
plt.plot(mask_histImage)
plt.show()

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐