Update bearbeite_fotos.py to final blend of Option 1 and 4
This commit is contained in:
1 parent
ad095f2a8a
commit
e41575062a
2 files changed
+14
-19
No files matched your search
+14
-19
@@ -1,16 +1,10 @@
|
||||
import os
|
||||
from PIL import Image, ImageEnhance
|
||||
from PIL import Image, ImageEnhance, ImageOps
|
||||
|
||||
# Pfade
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
INPUT_DIR = os.path.join(BASE_DIR, 'media', 'Schnappix')
|
||||
OUTPUT_DIR = os.path.join(BASE_DIR, 'media', 'Schnappix_Bearbeitet')
|
||||
|
||||
# Einstellungen zur Bildverbesserung
|
||||
# 1.0 ist das Originalbild. 1.3 bedeutet 30% mehr Sättigung.
|
||||
SATURATION_FACTOR = 1.4
|
||||
CONTRAST_FACTOR = 1.15 # Etwas mehr Kontrast hilft oft bei "blassen" Bildern
|
||||
|
||||
def process_images():
|
||||
if not os.path.exists(OUTPUT_DIR):
|
||||
os.makedirs(OUTPUT_DIR)
|
||||
@@ -18,36 +12,37 @@ def process_images():
|
||||
|
||||
processed_count = 0
|
||||
|
||||
# Alle Dateien im Eingangsordner durchlaufen
|
||||
for filename in os.listdir(INPUT_DIR):
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
|
||||
input_path = os.path.join(INPUT_DIR, filename)
|
||||
output_path = os.path.join(OUTPUT_DIR, filename)
|
||||
|
||||
# Überspringen, falls das Bild schon im Zielordner existiert
|
||||
if os.path.exists(output_path):
|
||||
continue
|
||||
|
||||
try:
|
||||
with Image.open(input_path) as img:
|
||||
# 1. Sättigung anpassen
|
||||
enhancer_color = ImageEnhance.Color(img)
|
||||
img_enhanced = enhancer_color.enhance(SATURATION_FACTOR)
|
||||
# Der bewährte Mix aus Option 1 und 4:
|
||||
|
||||
# 1. Auto-Kontrast (Entfernt den Grauschleier)
|
||||
img_step1 = ImageOps.autocontrast(img, cutoff=1)
|
||||
|
||||
# 2. Ganz leichte Aufhellung (damit es nicht zu dunkel wird)
|
||||
img_step2 = ImageEnhance.Brightness(img_step1).enhance(1.08)
|
||||
|
||||
# 3. Farbe leicht anheben (1.2 statt den extremen 1.4 vom allerersten Versuch)
|
||||
img_final = ImageEnhance.Color(img_step2).enhance(1.2)
|
||||
|
||||
# 2. Kontrast anpassen
|
||||
enhancer_contrast = ImageEnhance.Contrast(img_enhanced)
|
||||
img_final = enhancer_contrast.enhance(CONTRAST_FACTOR)
|
||||
|
||||
# Speichern (mit hoher Qualität)
|
||||
# Speichern
|
||||
img_final.save(output_path, quality=95)
|
||||
print(f"Bearbeitet: {filename}")
|
||||
processed_count += 1
|
||||
except Exception as e:
|
||||
print(f"Fehler bei {filename}: {e}")
|
||||
|
||||
print(f"\nFertig! {processed_count} neue Bilder wurden bearbeitet.")
|
||||
print(f"\nFertig! {processed_count} Bilder wurden bearbeitet.")
|
||||
print(f"Du findest sie hier: {OUTPUT_DIR}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Starte Bildbearbeitung...")
|
||||
print("Starte finale Bildbearbeitung...")
|
||||
process_images()
|
||||
Reference in new issue
Block a user