Created
July 2, 2024 19:23
-
-
Save Jademaster/2bb967ee856b22a582a6b07eebd23758 to your computer and use it in GitHub Desktop.
Copying/cooking my own version Akiyoshi Kitaoka's amazing art (see https://www.ritsumei.ac.jp/~akitaoka/index-e.html)
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
import math | |
from statistics import mean | |
from PIL import Image, ImageColor, ImageDraw | |
import sys | |
import numpy as np | |
import random | |
# Copying/cooking my own version Akiyoshi Kitaoka's amazing art (see https://www.ritsumei.ac.jp/~akitaoka/index-e.html) | |
filename='bird.png' | |
img = Image.open(filename) | |
output = Image.new("RGB", img.size) | |
drawer = ImageDraw.Draw(output) | |
def getaveragecolor(image): | |
return (int(mean(image.getdata(0))),int(mean(image.getdata(1))),int(mean(image.getdata(2)))) | |
def getbrightness(rgbvalue): | |
brightness = 0.2126*rgbvalue[0] + 0.7152 * rgbvalue[1] + 0.0722 * rgbvalue[2] | |
return brightness/255.0 | |
numlines = 30 | |
lineheight = img.size[1]/float(numlines) | |
lineresolution = 100 | |
linewidth = img.size[0]/float(lineresolution) | |
for i in range(numlines): | |
for j in range(lineresolution): | |
rectangle = img.crop((i*lineheight,j*linewidth,(i+1)*lineheight,(j+1)*linewidth)) | |
avgcolor = getaveragecolor(rectangle) | |
brightness = getbrightness(avgcolor) | |
drawer.rectangle([i*lineheight + (1-brightness)*lineheight,j*linewidth,(i+1)*lineheight,(j+1)*linewidth],fill=avgcolor,width=0) | |
output.show() | |
output.save(str(numlines)+filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment