Skip to content

Instantly share code, notes, and snippets.

@rinchik
Last active June 4, 2016 20:20
Show Gist options
  • Save rinchik/d023578a705d6d4a5b12e235c5a9df9a to your computer and use it in GitHub Desktop.
Save rinchik/d023578a705d6d4a5b12e235c5a9df9a to your computer and use it in GitHub Desktop.
Calculating image region brightess
def process_region(self, image, x, y, width, height):
region_total = 0
# This is the sensitivity factor, the larger it is the less sensitive the comparison
factor = 10
for coordinateY in range(y, y+height):
for coordinateX in range(x, x+width):
try:
pixel = image.getpixel((coordinateX, coordinateY))
region_total += sum(pixel)/4
except:
return
return region_total/factor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment