Skip to content

Instantly share code, notes, and snippets.

@bitdivision
Last active August 29, 2015 14:00
Show Gist options
  • Save bitdivision/11367112 to your computer and use it in GitHub Desktop.
Save bitdivision/11367112 to your computer and use it in GitHub Desktop.
Function to estimate focus in an image region
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