#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/06/19 22:11:22 +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)) gpixel = gim.load() opixel = oim.load() for y in range(height): for x in range(width): opixel[x, y] = 255 - gpixel[x, y] oim.show() oim.save("output_03getpixel2.png") if __name__ == '__main__': main()