mirror of
https://codeberg.org/vlw/collage.git
synced 2025-09-14 07:33:40 +02:00
dev21w12a
This commit is contained in:
parent
f0ea7e1c65
commit
090f68cd0e
10 changed files with 69 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
__pycache__
|
||||||
|
|
||||||
|
input/*
|
||||||
|
samples/*
|
||||||
|
mem/*
|
||||||
|
|
||||||
|
!*/.placeholder
|
24
classes/Eyedropper.py
Normal file
24
classes/Eyedropper.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
def compute_average_image_color(img):
|
||||||
|
width, height = img.size
|
||||||
|
|
||||||
|
r_total = 0
|
||||||
|
g_total = 0
|
||||||
|
b_total = 0
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for x in range(0, width):
|
||||||
|
for y in range(0, height):
|
||||||
|
r, g, b = img.getpixel((x,y))
|
||||||
|
r_total += r
|
||||||
|
g_total += g
|
||||||
|
b_total += b
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return (r_total/count, g_total/count, b_total/count)
|
||||||
|
|
||||||
|
img = Image.open('image.png')
|
||||||
|
#img = img.resize((50,50)) # Small optimization
|
||||||
|
average_color = compute_average_image_color(img)
|
||||||
|
print(average_color)
|
26
classes/Samples.py
Normal file
26
classes/Samples.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
class Samples:
|
||||||
|
def __init__(self,samples_path):
|
||||||
|
samples_files = Path(samples_path).glob("*.jpg")
|
||||||
|
self.samples = [x for x in samples_files if x.is_file()]
|
||||||
|
|
||||||
|
self.hash = self.create_hash()
|
||||||
|
self.memory = f"mem/{self.hash}"
|
||||||
|
|
||||||
|
# Create hash from sample names and path
|
||||||
|
def create_hash(self):
|
||||||
|
samples_hash = ""
|
||||||
|
for i in self.samples:
|
||||||
|
samples_hash = hash(i)
|
||||||
|
return samples_hash
|
||||||
|
|
||||||
|
# Test if the current sample set has been saved
|
||||||
|
def hash_exists(self):
|
||||||
|
if(Path(self.memory).is_file()):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Save hash to memory location on disk
|
||||||
|
def save_hash(self):
|
||||||
|
Path(self.memory,"w").touch()
|
0
classes/__init__.py
Normal file
0
classes/__init__.py
Normal file
4
create_collage.sh
Normal file
4
create_collage.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#! /bin/bash
|
||||||
|
export PYTHONHASHSEED=0
|
||||||
|
|
||||||
|
python3 main.py
|
0
input/.placeholder
Normal file
0
input/.placeholder
Normal file
7
main.py
Normal file
7
main.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#from classes import Eyedropper
|
||||||
|
from classes.Samples import Samples
|
||||||
|
|
||||||
|
# Load samples from folder
|
||||||
|
samples = Samples("samples")
|
||||||
|
|
||||||
|
print(samples.hash)
|
0
mem/.placeholder
Normal file
0
mem/.placeholder
Normal file
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Pillow
|
0
samples/.placeholder
Normal file
0
samples/.placeholder
Normal file
Loading…
Add table
Reference in a new issue