Files changed (1) hide show
  1. app.py +28 -31
app.py CHANGED
@@ -14,8 +14,8 @@ def remove_folds(image, intensity=0.5):
14
  l, a, b = cv2.split(img_lab)
15
 
16
  # --- (1) Smooth illumination correction ---
17
- ksize = int(49 + intensity * 100) # kernel size changes with intensity
18
- ksize = ksize + 1 if ksize % 2 == 0 else ksize # must be odd
19
  l_blur = cv2.GaussianBlur(l, (ksize, ksize), 0)
20
  l_equal = cv2.divide(l, l_blur, scale=128)
21
 
@@ -25,7 +25,7 @@ def remove_folds(image, intensity=0.5):
25
  rows, cols = l_equal.shape
26
  crow, ccol = rows // 2, cols // 2
27
  mask = np.ones((rows, cols), np.uint8)
28
- r = int(10 + intensity * 30) # notch size grows with intensity
29
  mask[crow - r:crow + r, ccol - r:ccol + r] = 0
30
  freqshift = freqshift * mask
31
  ishift = np.fft.ifftshift(freqshift)
@@ -38,35 +38,32 @@ def remove_folds(image, intensity=0.5):
38
  return Image.fromarray(result)
39
 
40
  # -------------------------------------------------
41
- # πŸŽ›οΈ GRADIO UI
42
  # -------------------------------------------------
43
- title = "πŸͺ„ Saree Fold Remover (Lighting Only, No Distortion)"
44
- description = """
45
- Upload a flat saree or fabric image.<br>
46
- Adjust the **Fold Intensity** slider β€” higher values remove deeper folds.<br>
47
- The process equalizes lighting only, keeping weave and motifs intact.
48
- """
 
 
 
49
 
50
- iface = gr.Interface(
51
- fn=remove_folds,
52
- inputs=[
53
- gr.Image(label="Upload Saree Image", type="pil"),
54
- gr.Slider(
55
- 0.0,
56
- 1.0,
57
- value=0.5,
58
- step=0.05,
59
  label="Fold Intensity",
60
- info="Higher = stronger flattening (lighting only)",
61
- interactive=True
62
- ),
63
- ],
64
- outputs=gr.Image(label="Flat, Fold-Free Output"),
65
- title=title,
66
- description=description,
67
- live=False, # prevents rerun while moving
68
- throttle=0.8 # waits 0.8 s before triggering
69
- )
70
 
71
- if __name__ == "__main__":
72
- iface.launch()
 
 
 
 
 
 
 
 
14
  l, a, b = cv2.split(img_lab)
15
 
16
  # --- (1) Smooth illumination correction ---
17
+ ksize = int(49 + intensity * 100)
18
+ ksize = ksize + 1 if ksize % 2 == 0 else ksize
19
  l_blur = cv2.GaussianBlur(l, (ksize, ksize), 0)
20
  l_equal = cv2.divide(l, l_blur, scale=128)
21
 
 
25
  rows, cols = l_equal.shape
26
  crow, ccol = rows // 2, cols // 2
27
  mask = np.ones((rows, cols), np.uint8)
28
+ r = int(10 + intensity * 30)
29
  mask[crow - r:crow + r, ccol - r:ccol + r] = 0
30
  freqshift = freqshift * mask
31
  ishift = np.fft.ifftshift(freqshift)
 
38
  return Image.fromarray(result)
39
 
40
  # -------------------------------------------------
41
+ # πŸŽ›οΈ GRADIO BLOCKS UI (with slider throttle)
42
  # -------------------------------------------------
43
+ with gr.Blocks(title="πŸͺ„ Saree Fold Remover (Lighting Only, No Distortion)") as demo:
44
+ gr.Markdown(
45
+ """
46
+ ## πŸͺ„ Saree Fold Remover
47
+ Upload a flat saree or fabric image.<br>
48
+ Adjust the **Fold Intensity** slider β€” higher values remove deeper folds.<br>
49
+ Lighting only correction, no geometric distortion.
50
+ """
51
+ )
52
 
53
+ with gr.Row():
54
+ inp = gr.Image(label="Upload Saree Image", type="pil")
55
+ intensity = gr.Slider(
56
+ 0.0, 1.0, value=0.5, step=0.05,
 
 
 
 
 
57
  label="Fold Intensity",
58
+ info="Higher = stronger flattening (lighting only)"
59
+ )
 
 
 
 
 
 
 
 
60
 
61
+ out = gr.Image(label="Flat, Fold-Free Output")
62
+
63
+ # Button to trigger with throttle behavior
64
+ run_btn = gr.Button("✨ Remove Folds")
65
+
66
+ # Run when button is pressed (instead of live refresh)
67
+ run_btn.click(fn=remove_folds, inputs=[inp, intensity], outputs=out)
68
+
69
+ demo.launch()