Skip to content

Instantly share code, notes, and snippets.

@otakbeku
Created June 22, 2020 11:57
Show Gist options
  • Select an option

  • Save otakbeku/0eb8de9565f919809d34d6f885e9fd09 to your computer and use it in GitHub Desktop.

Select an option

Save otakbeku/0eb8de9565f919809d34d6f885e9fd09 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import cv2
img = cv2.imread('/path/')
split_img = cv2.split(img) # Splitting channel
histSize = 256
histRange = (0, 256) # the upper boundary is exclusive
accumulate = False
histr1 = cv2.calcHist(split_img, [0], None, [histSize], histRange, accumulate=accumulate)
histr2 = cv2.calcHist(split_img, [1], None, [histSize], histRange, accumulate=accumulate)
histr3 = cv2.calcHist(split_img, [2], None, [histSize], histRange, accumulate=accumulate)
fig, ax = plt.subplots()
ax.plot(histr1, color='cyan', label='Color 1')
ax.plot(histr2, color='red', label='Color 2')
ax.plot(histr3, color='blue', label='Colo 3')
ax.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment