1:#!/usr/bin/python
2:# Isaias Gonzalez <siderevs [at] gmail.com>
3:from PIL import Image
4:import sys
5:import os
6:
7:def makehistogram(filename, outfilename):
8: img = Image.open(filename).convert("L")
9: liH = img.histogram()
10: maxval = max(liH)
11: hist = Image.new("L", (256, 60),256)
12:
13: for i in range(256):
14: #normalization
15: y = liH[i]*50/maxval
16: #give an up and bottom padding of 5
17: y = 55 - y
18: hist.putpixel((i,y),0)
19:
20: hist.show()
21: hist.save(outfilename)
22:
23:if __name__ == "__main__":
24: if len(sys.argv) != 3:
25: sys.exit("Usage: %s <inputimage> <outputimage>"
26: % os.path.basename(sys.argv[0]))
27: makehistogram(*sys.argv[1:])
Sólo texto