1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
import Image
import matplotlib.pyplot as plt
import sys
filename = sys.argv[1]
im = Image.open(filename)
data = list(im.getdata())
r,g,b = im.split()
red = r.getdata()
green = g.getdata()
blue = b.getdata()
if '-s' in sys.argv:
size = range(256)
plt.title('intensity')
plt.plot(size,r.histogram(),'r')
plt.plot(size,g.histogram(),'g')
plt.plot(size,b.histogram(),'b')
plt.show()
if '-o' in sys.argv:
o = open(filename + '.csv','w')
o.write('r\tg\tb\n')
hr = r.histogram()
hg = g.histogram()
hb = b.histogram()
for d in xrange(255):
o.write('%s\t%s\t%s\n' % (hr[d],hg[d],hb[d]))
o.close() |
Partager