Add test_enhancements_2 with new variations

This commit is contained in:
Jannik committed 2026-09-21 22:14:11 +02:00
1 parent 1bddb484ac
commit 84d451eab6
4 files changed
+90

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 KiB

+90
View File
@@ -0,0 +1,90 @@
import os
import cv2
import numpy as np
from PIL import Image, ImageEnhance, ImageOps
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
INPUT_FILE = os.path.join(BASE_DIR, 'media', 'Schnappix', 'HochzeitNeleTill_2026-09-19_21-10-30_Raw.jpg')
TEST_DIR = os.path.join(BASE_DIR, 'media', 'Schnappix_Test')
if not os.path.exists(TEST_DIR):
os.makedirs(TEST_DIR)
def test_option_4_brillanz(input_path, output_path):
"""Option 4: Brillanz - Sanfte Aufhellung, Kontrast und Sättigung (PIL)"""
try:
with Image.open(input_path) as img:
# Etwas aufhellen
img = ImageEnhance.Brightness(img).enhance(1.15)
# Etwas Kontrast
img = ImageEnhance.Contrast(img).enhance(1.05)
# Etwas Sättigung (ähnlich wie bei Option 1)
img = ImageEnhance.Color(img).enhance(1.2)
img.save(output_path, quality=95)
except Exception as e:
print(f"Fehler Option 4: {e}")
def test_option_5_weissabgleich(input_path, output_path):
"""Option 5: Automatischer Weißabgleich (Grayworld) - fixt Farbstiche bei schlechtem Licht"""
try:
img = cv2.imread(input_path)
# Grayworld Assumption: Durchschnitt der Farben angleichen
b, g, r = cv2.split(img.astype(np.float32))
m_b = np.mean(b)
m_g = np.mean(g)
m_r = np.mean(r)
# Durchschnitt über alles
m = (m_b + m_g + m_r) / 3.0
# Anpassen der Kanäle, um Farbstich (z.B. gelbes Raumlicht) zu entfernen
b = np.clip(b * (m / m_b), 0, 255)
g = np.clip(g * (m / m_g), 0, 255)
r = np.clip(r * (m / m_r), 0, 255)
balanced = cv2.merge((b, g, r)).astype(np.uint8)
# Anschließend noch leicht Sättigung anheben (da Option 1 gut ankam)
hsv = cv2.cvtColor(balanced, cv2.COLOR_BGR2HSV).astype(np.float32)
h, s, v = cv2.split(hsv)
s = np.clip(s * 1.15, 0, 255)
hsv = cv2.merge((h, s, v)).astype(np.uint8)
final = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(output_path, final, [cv2.IMWRITE_JPEG_QUALITY, 95])
except Exception as e:
print(f"Fehler Option 5: {e}")
def test_option_6_gamma_korrekt(input_path, output_path):
"""Option 6: Echte Schatten-Aufhellung durch korrektes Gamma > 1"""
try:
img = cv2.imread(input_path)
# Gamma > 1 hellt auf (mein vorheriger Fehler, sry!)
gamma = 1.4
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
gamma_img = cv2.LUT(img, table)
# Leichte Sättigung
hsv = cv2.cvtColor(gamma_img, cv2.COLOR_BGR2HSV).astype(np.float32)
h, s, v = cv2.split(hsv)
s = np.clip(s * 1.15, 0, 255)
hsv = cv2.merge((h, s, v)).astype(np.uint8)
final_img = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(output_path, final_img, [cv2.IMWRITE_JPEG_QUALITY, 95])
except Exception as e:
print(f"Fehler Option 6: {e}")
if __name__ == '__main__':
if os.path.exists(INPUT_FILE):
print("Erstelle Test-Varianten 4 bis 6...")
test_option_4_brillanz(INPUT_FILE, os.path.join(TEST_DIR, 'Option_4_Brillanz.jpg'))
test_option_5_weissabgleich(INPUT_FILE, os.path.join(TEST_DIR, 'Option_5_Weissabgleich.jpg'))
test_option_6_gamma_korrekt(INPUT_FILE, os.path.join(TEST_DIR, 'Option_6_Aufgehellt_Gamma.jpg'))
print("Neue Varianten erstellt!")
else:
print(f"Datei nicht gefunden: {INPUT_FILE}")