Created
August 29, 2017 04:29
-
-
Save takapiko/316fe6d190bc22abdbc16397b510fbf5 to your computer and use it in GitHub Desktop.
補色残像による錯視画像の生成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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