File size: 527 Bytes
b17203c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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")