Skip to content

Instantly share code, notes, and snippets.

@takapiko
Created August 29, 2017 04:29
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 takapiko/316fe6d190bc22abdbc16397b510fbf5 to your computer and use it in GitHub Desktop.
Save takapiko/316fe6d190bc22abdbc16397b510fbf5 to your computer and use it in GitHub Desktop.
補色残像による錯視画像の生成
# coding: UTF-8
import sys
from PIL import Image
if __name__ == "__main__":
filename = sys.argv[1]
raw_img = Image.open(filename,'r')
gray_img = raw_img.convert('L')
size = raw_img.size
comp_img = Image.new('RGB',size)
for x in range(size[0]):
for y in range(size[1]):
pixel = raw_img.getpixel((x,y))
sum_max_min = max(pixel) + min(pixel)
pixel_comp = tuple([sum_max_min - c for c in pixel])
comp_img.putpixel((x,y),pixel_comp)
gray_img.save('gray_'+filename)
comp_img.save("comp_"+filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment