Skip to content

Instantly share code, notes, and snippets.

@vizowl
Last active August 29, 2015 14:16
Show Gist options
  • Save vizowl/286cc3cfa6cc3f977bac to your computer and use it in GitHub Desktop.
Save vizowl/286cc3cfa6cc3f977bac to your computer and use it in GitHub Desktop.
Image histogram
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
img=mpimg.imread('image.jpg')
lum_img = img[:,:,0]
p = plt.hist(lum_img.flatten(), 256, range=(0.0,255), fc='k', ec='k')
plt.savefig('out.png')
@edwardabraham
Copy link

Try range=(0, 255) for a more exciting plot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment