使用掩膜绘制图像直方图opencv的python实现

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

发布了45 篇原创文章 · 获赞 24 · 访问量 3418

猜你喜欢

转载自blog.csdn.net/my_name_is_learn/article/details/104036243