File size: 454 Bytes
b9e0048
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import cv2
import numpy as np

def preprocess_image(image: np.ndarray) -> np.ndarray:
    # Convert to LAB color space and apply CLAHE
    lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
    clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8))
    lab[:, :, 0] = clahe.apply(lab[:, :, 0])
    enhanced = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)

    # Apply bilateral filtering
    denoised = cv2.bilateralFilter(enhanced, 9, 75, 75)

    return denoised