Skip to content

Instantly share code, notes, and snippets.

@Praveen76
Last active April 15, 2022 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Praveen76/7de750d4872182239890f162d89eb30d to your computer and use it in GitHub Desktop.
Save Praveen76/7de750d4872182239890f162d89eb30d to your computer and use it in GitHub Desktop.
img=cv.imread('D:\cats.jpg')
cv.imshow('img','img)
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow('gray',gray)
#gray hist
gray_hist=cv.calcHist([gray],[0],None,[256],[0,256])
fig,axs=plt.subplots(2)
axs[0].plot(gray_hist)
axs.flat[0].set(xlabel='Bins',ylabel='no. of pixels')
plt.xlim(0,256)
#Color Histogram
colors=('b','g','r')
for i,col in enumerate(colors):
hist=cv.calcHist([img],[i],None,[256],[0,256])
axs[1].plot(hist,olor=color)
axs.flat[1].set(xlabel='Bins',ylabel='no. of pixels')
plt.xlim(0,256)
plt.show()
cv.waitKey(0)
cv.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment