Skip to content

Instantly share code, notes, and snippets.

@KramKroc
Created December 10, 2017 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KramKroc/ea2c4aebd1db6ebd676d2b7b970b2ff4 to your computer and use it in GitHub Desktop.
Save KramKroc/ea2c4aebd1db6ebd676d2b7b970b2ff4 to your computer and use it in GitHub Desktop.
Using the Pillow module to calculate average brightness of an image
import io
import time
import picamera
from PIL import Image
from PIL import ImageStat
stream = io.BytesIO()
with picamera.PiCamera() as camera:
camera.start_preview()
time.sleep(2)
camera.capture(stream, format='jpeg')
stream.seek(0)
image = Image.open(stream).convert('L')
stat = ImageStat.Stat(image)
print("Brighness of image: ", stat.mean[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment