55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
import os
|
|
import cv2
|
|
import numpy as np
|
|
from PIL import Image, ImageEnhance, ImageOps
|
|
|
|
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_Smart_Bearbeitet')
|
|
|
|
def process_images():
|
|
if not os.path.exists(OUTPUT_DIR):
|
|
os.makedirs(OUTPUT_DIR)
|
|
print(f"Ordner erstellt: {OUTPUT_DIR}")
|
|
|
|
processed_count = 0
|
|
|
|
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)
|
|
|
|
if os.path.exists(output_path):
|
|
continue
|
|
|
|
try:
|
|
# 1. Bilateraler Filter (OpenCV)
|
|
# Entfernt Rauschen (Körnung), aber ERHÄLT Kanten extrem scharf (anders als der vorherige Filter)
|
|
img_cv = cv2.imread(input_path)
|
|
|
|
# d=9 (Pixel-Nachbarschaft), sigmaColor=75 (wie stark Farben gemischt werden dürfen), sigmaSpace=75
|
|
img_smoothed = cv2.bilateralFilter(img_cv, d=9, sigmaColor=75, sigmaSpace=75)
|
|
|
|
# Konvertieren zu PIL für die Farbkorrektur
|
|
img_rgb = cv2.cvtColor(img_smoothed, cv2.COLOR_BGR2RGB)
|
|
img_pil = Image.fromarray(img_rgb)
|
|
|
|
# 2. Farb- und Kontrastkorrektur (Dein Favorit)
|
|
img_step1 = ImageOps.autocontrast(img_pil, cutoff=1)
|
|
img_step2 = ImageEnhance.Brightness(img_step1).enhance(1.08)
|
|
img_final = ImageEnhance.Color(img_step2).enhance(1.2)
|
|
|
|
# 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} Bilder wurden bearbeitet.")
|
|
print(f"Du findest sie hier: {OUTPUT_DIR}")
|
|
|
|
if __name__ == '__main__':
|
|
print("Starte smarte Bildbearbeitung (Bilateraler Filter + Color Boost)...")
|
|
process_images()
|