Get and put

putpixel and getpixel.

putpixel / getpixel are slow on purpose — fine on a 20×20 teaching grid.

Goal

Draw a red diagonal and print one pixel.

from PIL import Image
im = Image.new('RGB', (20, 20), (0, 0, 0))
for i in range(20):
    im.putpixel((i, i), (200, 40, 40))
print(im.getpixel((5, 5)))
plt.imshow(im)
plt.axis('off')
plt.show()
from PIL import Image
im = Image.new('RGB', (8, 8), (255, 255, 255))
print(im.getpixel((0, 0)))
from PIL import Image
im = Image.new('L', (4, 4), 0)
im.putpixel((1, 1), 255)
print(list(im.getdata())[:8])
from PIL import Image
im = Image.new('RGB', (10, 10), (0, 0, 0))
im.putpixel((2, 3), (0, 128, 64))
print(im.getpixel((2, 3)))