1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
import cv2 import numpy as np import matplotlib.pyplot as plt
input_filepath = 'Lenna.png' img = cv2.imread(input_filepath)
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) hist = [cv2.calcHist([imgRGB], [k], None, [256], [0, 256]) for k in range(3)] x = np.arange(256) + 0.5 plt.subplot(221), plt.imshow(imgRGB) plt.subplot(222), plt.bar(x, hist[0], color = 'r', edgecolor = 'r') plt.subplot(223), plt.bar(x, hist[1], color = 'g', edgecolor = 'g') plt.subplot(224), plt.bar(x, hist[2], color = 'b', edgecolor = 'b') plt.show()
imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) hist = [cv2.calcHist([imgHSV], [0], None, [50], [0, 180]), \ cv2.calcHist([imgHSV], [1], None, [50], [0, 256])] x = np.arange(50) + 0.5 plt.subplot(211), plt.bar(x, hist[0]) plt.subplot(212), plt.bar(x, hist[1]) plt.show()
|