/usr/lib/python2.7/dist-packages/piggyphoto/focus.py is in python-piggyphoto 0.1dev-git20141014.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import Image, ImageFilter, ImageChops, ImageStat
import time
def estimate(file, s=5):
"""Estimates the amount of focus of an image file.
Returns a real number: lower values indicate better focus.
"""
im = Image.open(file).convert("L")
w,h = im.size
box = (w/2 - 50, h/2 - 50, w/2 + 50, h/2 + 50)
im = im.crop(box)
imf = im.filter(ImageFilter.MedianFilter(s))
d = ImageChops.subtract(im, imf, 1, 100)
return ImageStat.Stat(d).stddev[0]
if __name__ == "__main__":
t = time.time()
print eval_focus("preview.jpg")
print time.time()-t
|