Files
Smartwave/cloud/image_enhancer.py
T
Ninluc 3711928c7d
Build, push image, and notify Watchtower / build-image (push) Successful in 41s
Build, push image, and notify Watchtower / notify (push) Successful in 14s
Enhance image before ai processing
2026-08-23 12:33:39 +02:00

23 lines
763 B
Python

import cv2
def enhance_image_for_ai(input_path: str) -> str:
"""Enhances dark areas and contrast using CLAHE without blowing out bright areas."""
img = cv2.imread(input_path)
if img is None:
return input_path
# Convert to LAB color space to modify luminance channel only
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
# Apply CLAHE to Lightness channel
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8))
cl = clahe.apply(l)
# Merge channels and convert back to BGR
limg = cv2.merge((cl, a, b))
enhanced = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
enhanced_path = input_path.replace(".jpg", "_enhanced.jpg")
cv2.imwrite(enhanced_path, enhanced)
return enhanced_path