Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2, numpy as np
3
+ from PIL import Image
4
+
5
+ def uniform_lighting(image):
6
+ # Convert PIL → OpenCV
7
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
8
+
9
+ # 1️⃣ Convert to grayscale to estimate illumination
10
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11
+
12
+ # 2️⃣ Smooth illumination field (large Gaussian kernel)
13
+ illumination = cv2.GaussianBlur(gray, (51, 51), 0)
14
+
15
+ # 3️⃣ Compute normalization map using brightest region
16
+ brightest = np.max(illumination)
17
+ illum_norm = brightest / (illumination + 1e-5)
18
+ illum_norm = np.repeat(illum_norm[:, :, np.newaxis], 3, axis=2)
19
+
20
+ # 4️⃣ Apply correction
21
+ corrected = np.clip(img.astype(np.float32) * illum_norm, 0, 255).astype(np.uint8)
22
+
23
+ # Convert back to PIL for Gradio display
24
+ corrected_rgb = cv2.cvtColor(corrected, cv2.COLOR_BGR2RGB)
25
+ return Image.fromarray(corrected_rgb)
26
+
27
+ title = "🧵 Saree AI – Uniform Lighting Correction"
28
+ description = """
29
+ Upload a saree image with uneven lighting.
30
+ This tool will automatically detect illumination gradients and normalize brightness
31
+ using the brightest region as reference, giving you a flat, uniform look for catalog or dataset use.
32
+ """
33
+
34
+ demo = gr.Interface(
35
+ fn=uniform_lighting,
36
+ inputs=gr.Image(label="Upload Saree Image", type="pil"),
37
+ outputs=gr.Image(label="Corrected Image"),
38
+ title=title,
39
+ description=description,
40
+ examples=[],
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ demo.launch()