YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -0,0 +1,42 @@
from PIL import Image
# Open the image
image = Image.open("lena.jpg")
# Get the width and height of the image
width, height = image.size
# Calculate the amount of pixels
amount = width * height
# Total amount of greyscale
total = 0
# B/W image
bw_image = Image.new('L', (width, height), 0)
# Bitmap image
bm_image = Image.new('1', (width, height), 0)
for h in range(0, height):
for w in range(0, width):
r, g, b = image.getpixel((w, h))
greyscale = int((r + g + b) / 3)
total += greyscale
bw_image.putpixel((w, h), gray_scale)
# The average greyscale
avg = total / amount
black = 0
white = 1
for h in range(0, height):
for w in range(0, width):
v = bw_image.getpixel((w, h))
if v >= avg:
bm_image.putpixel((w, h), white)
else:
bm_image.putpixel((w, h), black)
bw_image.show()
bm_image.show()