#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/06/19 22:06:24 +0900> """ Pillow .getpixel(), .putpixel() sample Windows10 x64 21H2 + Python 3.9.13 64bit + Pillow 9.1.1 """ from PIL import Image def main(): im = Image.open("mandrill.png") width, height = im.size print("%d x %d" % (width, height)) gim = im.convert("L") oim = Image.new("L", (width, height)) for y in range(height): for x in range(width): v = 255 - gim.getpixel((x, y)) oim.putpixel((x, y), (v)) oim.show() oim.save("output_02getpixel.png") if __name__ == '__main__': main()