Add test_enhancements_3 focusing on noise reduction
This commit is contained in:
1 parent
84d451eab6
commit
ad095f2a8a
4 files changed
+70
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 430 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 461 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 485 KiB |
@@ -0,0 +1,70 @@
|
||||
import os
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image, ImageOps, ImageEnhance
|
||||
|
||||
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 apply_denoising(input_path, h_val=12):
|
||||
"""Liest das Bild und wendet den OpenCV Denoising-Algorithmus an"""
|
||||
img = cv2.imread(input_path)
|
||||
# fastNlMeansDenoisingColored ist hervorragend gegen ISO-Rauschen (Körnung)
|
||||
# h_val bestimmt die Stärke der Entrauschung
|
||||
denoised = cv2.fastNlMeansDenoisingColored(img, None, h=h_val, hColor=h_val, templateWindowSize=7, searchWindowSize=21)
|
||||
|
||||
# Zurück zu PIL Format für weitere Bearbeitung
|
||||
denoised_rgb = cv2.cvtColor(denoised, cv2.COLOR_BGR2RGB)
|
||||
return Image.fromarray(denoised_rgb)
|
||||
|
||||
def test_option_7_nur_entrauscht(input_path, output_path):
|
||||
"""Option 7: Nur stark entrauscht, um den Effekt zu zeigen + minimale Aufhellung"""
|
||||
try:
|
||||
pil_img = apply_denoising(input_path, h_val=15)
|
||||
# Nur minimal aufhellen, damit es nicht zu dunkel wirkt
|
||||
img = ImageEnhance.Brightness(pil_img).enhance(1.1)
|
||||
img.save(output_path, quality=95)
|
||||
except Exception as e:
|
||||
print(f"Fehler Option 7: {e}")
|
||||
|
||||
def test_option_8_entrauscht_plus_opt1(input_path, output_path):
|
||||
"""Option 8: Entrauscht (mittlere Stärke) + Option 1 (AutoKontrast & Farbe)"""
|
||||
try:
|
||||
pil_img = apply_denoising(input_path, h_val=12)
|
||||
# Auto-Kontrast (wie Option 1)
|
||||
img_auto = ImageOps.autocontrast(pil_img, cutoff=1)
|
||||
# Farbe anheben (wie Option 1)
|
||||
img_final = ImageEnhance.Color(img_auto).enhance(1.2)
|
||||
|
||||
img_final.save(output_path, quality=95)
|
||||
except Exception as e:
|
||||
print(f"Fehler Option 8: {e}")
|
||||
|
||||
def test_option_9_entrauscht_scharf(input_path, output_path):
|
||||
"""Option 9: Entrauscht + Option 1 + nachgeschärft (da Entrauschen etwas weich macht)"""
|
||||
try:
|
||||
pil_img = apply_denoising(input_path, h_val=12)
|
||||
img_auto = ImageOps.autocontrast(pil_img, cutoff=1)
|
||||
img_color = ImageEnhance.Color(img_auto).enhance(1.2)
|
||||
|
||||
# Schärfen
|
||||
img_final = ImageEnhance.Sharpness(img_color).enhance(1.5)
|
||||
|
||||
img_final.save(output_path, quality=95)
|
||||
except Exception as e:
|
||||
print(f"Fehler Option 9: {e}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if os.path.exists(INPUT_FILE):
|
||||
print("Erstelle Test-Varianten 7 bis 9 (Entrauschung)...")
|
||||
print("Hinweis: Denoising ist rechenintensiv, das kann ein paar Sekunden dauern.")
|
||||
test_option_7_nur_entrauscht(INPUT_FILE, os.path.join(TEST_DIR, 'Option_7_Nur_Entrauscht.jpg'))
|
||||
test_option_8_entrauscht_plus_opt1(INPUT_FILE, os.path.join(TEST_DIR, 'Option_8_Entrauscht_und_Opt1.jpg'))
|
||||
test_option_9_entrauscht_scharf(INPUT_FILE, os.path.join(TEST_DIR, 'Option_9_Entrauscht_Opt1_Scharf.jpg'))
|
||||
print("Neue Varianten (Anti-Rauschen) erstellt!")
|
||||
else:
|
||||
print(f"Datei nicht gefunden: {INPUT_FILE}")
|
||||
Reference in new issue
Block a user