Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import cv2, numpy as np | |
| from PIL import Image | |
| def uniform_lighting(image): | |
| # Convert PIL → OpenCV | |
| img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) | |
| # 1️⃣ Convert to grayscale to estimate illumination | |
| gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
| # 2️⃣ Smooth illumination field (large Gaussian kernel) | |
| illumination = cv2.GaussianBlur(gray, (51, 51), 0) | |
| # 3️⃣ Compute normalization map using brightest region | |
| brightest = np.max(illumination) | |
| illum_norm = brightest / (illumination + 1e-5) | |
| illum_norm = np.repeat(illum_norm[:, :, np.newaxis], 3, axis=2) | |
| # 4️⃣ Apply correction | |
| corrected = np.clip(img.astype(np.float32) * illum_norm, 0, 255).astype(np.uint8) | |
| # Convert back to PIL for Gradio display | |
| corrected_rgb = cv2.cvtColor(corrected, cv2.COLOR_BGR2RGB) | |
| return Image.fromarray(corrected_rgb) | |
| title = "🧵 Saree AI – Uniform Lighting Correction" | |
| description = """ | |
| Upload a saree image with uneven lighting. | |
| This tool will automatically detect illumination gradients and normalize brightness | |
| using the brightest region as reference, giving you a flat, uniform look for catalog or dataset use. | |
| """ | |
| demo = gr.Interface( | |
| fn=uniform_lighting, | |
| inputs=gr.Image(label="Upload Saree Image", type="pil"), | |
| outputs=gr.Image(label="Corrected Image"), | |
| title=title, | |
| description=description, | |
| examples=[], | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |