Created
July 17, 2013 20:18
-
-
Save cedricbonhomme/6024068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import pylab | |
import glob | |
from collections import Counter | |
from PIL import Image | |
from PIL.ExifTags import TAGS | |
DIRECTORY = "/home/cedric/vienna/*.JPG" | |
def get_exif(fn): | |
ret = {} | |
i = Image.open(fn) | |
info = i._getexif() | |
if info is not None: | |
for tag, value in info.items(): | |
decoded = TAGS.get(tag, tag) | |
ret[decoded] = value | |
return ret | |
if __name__ == "__main__": | |
cnt = Counter() | |
pictures = glob.glob(DIRECTORY) | |
focal = Counter() | |
for picture in pictures: | |
exif = get_exif(picture) | |
if exif != {}: | |
focal[exif['FocalLength'][0]] += 1 | |
if focal: | |
length = len(focal) | |
ind = pylab.arange(length) | |
width = 0.35 # bars width | |
focal_list = [elem for elem in focal.keys()] | |
focal_count = [elem for elem in focal.values()] | |
max_focal_count = max(focal_count) # max focal_count | |
p = pylab.bar(ind, focal_count, width, color='r') | |
pylab.ylabel("Number of shots") | |
pylab.xlabel("Focal length") | |
pylab.title("Focal length repartition for " + str(sum(focal_count)) + " pictures") | |
pylab.xticks(ind + (width / 2), focal_list) | |
pylab.xlim(-width, len(ind)) | |
# changing the ordinate scale according to the max. | |
if max_focal_count <= 100: | |
pylab.ylim(0, max_focal_count + 5) | |
pylab.yticks(pylab.arange(0, max_focal_count + 5, 5)) | |
elif max_focal_count <= 200: | |
pylab.ylim(0, max_focal_count + 10) | |
pylab.yticks(pylab.arange(0, max_focal_count + 10, 10)) | |
elif max_focal_count <= 600: | |
pylab.ylim(0, max_focal_count + 25) | |
pylab.yticks(pylab.arange(0, max_focal_count + 25, 25)) | |
elif max_focal_count <= 800: | |
pylab.ylim(0, max_focal_count + 50) | |
pylab.yticks(pylab.arange(0, max_focal_count + 50, 50)) | |
for rect in p: | |
height = rect.get_height() | |
pylab.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), | |
ha='center', va='bottom') | |
pylab.show() | |
else: | |
print "No result." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment