Lab1 / image_parser.py
friedeggy's picture
Update image_parser.py
b17203c verified
Raw History Blame Contribute Delete
527 Bytes
import gradio as gr
import os
from PIL import Image
folder = "images"
img_list = os.listdir(folder)
#looks at the colors in an image and saves the findings to a file
with open("imageRGBs.txt", 'w') as color_file:
for image_name in img_list:
im = Image.open(folder+"/"+image_name)
#Returns the three main colors of the image
im2 = im.quantize(colors=3, method=2)
rgb = im2.getpalette()[:9]
b = list(map(str, rgb))
color_file.write(' '.join(b) + ";" + image_name + "\n")