Use a mask to draw the image histogram of python opencv achieve

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()

Published 45 original articles · won praise 24 · views 3418

Guess you like

Origin blog.csdn.net/my_name_is_learn/article/details/104036243