Last active
August 29, 2015 14:00
-
-
Save bitdivision/11367112 to your computer and use it in GitHub Desktop.
Function to estimate focus in an image region
This file contains hidden or 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
def estimateFocus(file, s=5): | |
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment