cr8 commited on
Commit
bf55f48
·
verified ·
1 Parent(s): faa80dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -1,34 +1,42 @@
1
  import gradio as gr
2
  from PIL import Image, ImageEnhance
3
 
4
- def enhance_image(image, vibrancy_factor, sharpness_factor, yellow_reducer, brightness_boost):
 
 
 
 
 
 
 
5
  image = image.convert("RGB")
6
 
7
- # Targeted yellow reduction (without blue boost)
8
  yellow_matrix = (
9
- 1.0 - yellow_reducer*0.3, 0, 0, 0, # Reduce red contribution
10
- 0, 1.0 - yellow_reducer*0.5, 0, 0, # Reduce green more (main yellow component)
11
- 0, 0, 1.0, 0 # Leave blue unchanged
12
  )
13
  image = image.convert("RGB", yellow_matrix)
14
 
15
- # Apply magenta reduction
16
  magenta_matrix = (
17
- 1.0 - yellow_reducer*0.2, 0, 0, 0, # Slight red reduction
18
- 0, 1.0 + yellow_reducer*0.3, 0, 0, # Boost green to counteract magenta
19
- 0, 0, 1.0 - yellow_reducer*0.2, 0 # Slight blue reduction
20
  )
21
  image = image.convert("RGB", magenta_matrix)
22
 
23
  # Apply brightness boost
24
- image = ImageEnhance.Brightness(image).enhance(1.0 + brightness_boost)
 
25
 
26
  # Apply vibrancy enhancements
27
- image = ImageEnhance.Color(image).enhance(vibrancy_factor)
28
- image = ImageEnhance.Contrast(image).enhance(1.0 + (vibrancy_factor-1)*0.1)
29
 
30
  # Apply sharpness last
31
- image = ImageEnhance.Sharpness(image).enhance(sharpness_factor)
32
 
33
  return image
34
 
@@ -38,12 +46,13 @@ iface = gr.Interface(
38
  gr.Image(type="pil", label="Original Image"),
39
  gr.Slider(0.5, 2.0, 1.0, step=0.1, label="Vibrancy"),
40
  gr.Slider(0.5, 3.0, 1.0, step=0.1, label="Sharpness"),
41
- gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Yellow/Magenta Reduction"),
 
42
  gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Brightness Boost")
43
  ],
44
  outputs=gr.Image(type="pil", label="Enhanced Image", format="jpeg"),
45
- title="Professional Image Enhancer",
46
- description="Targeted yellow/magenta removal with natural color preservation"
47
  )
48
 
49
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from PIL import Image, ImageEnhance
3
 
4
+ def enhance_image(image,
5
+ vibrancy=1.0,
6
+ sharpness=1.0,
7
+ yellow_reduce=0.0,
8
+ magenta_reduce=0.0,
9
+ brightness=0.0):
10
+
11
+ # Convert to RGB
12
  image = image.convert("RGB")
13
 
14
+ # Yellow reduction matrix (targets red/green channels)
15
  yellow_matrix = (
16
+ 1.0 - yellow_reduce*0.4, 0, 0, 0,
17
+ 0, 1.0 - yellow_reduce*0.6, 0, 0,
18
+ 0, 0, 1.0 + yellow_reduce*0.2, 0 # Compensate with slight blue
19
  )
20
  image = image.convert("RGB", yellow_matrix)
21
 
22
+ # Magenta reduction matrix (targets red/blue channels)
23
  magenta_matrix = (
24
+ 1.0 - magenta_reduce*0.3, 0, 0, 0,
25
+ 0, 1.0 + magenta_reduce*0.4, 0, 0,
26
+ 0, 0, 1.0 - magenta_reduce*0.3, 0
27
  )
28
  image = image.convert("RGB", magenta_matrix)
29
 
30
  # Apply brightness boost
31
+ if brightness > 0:
32
+ image = ImageEnhance.Brightness(image).enhance(1.0 + brightness)
33
 
34
  # Apply vibrancy enhancements
35
+ image = ImageEnhance.Color(image).enhance(vibrancy)
36
+ image = ImageEnhance.Contrast(image).enhance(1.0 + (vibrancy-1)*0.15)
37
 
38
  # Apply sharpness last
39
+ image = ImageEnhance.Sharpness(image).enhance(sharpness)
40
 
41
  return image
42
 
 
46
  gr.Image(type="pil", label="Original Image"),
47
  gr.Slider(0.5, 2.0, 1.0, step=0.1, label="Vibrancy"),
48
  gr.Slider(0.5, 3.0, 1.0, step=0.1, label="Sharpness"),
49
+ gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Yellow Reduction"),
50
+ gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Magenta Reduction"),
51
  gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Brightness Boost")
52
  ],
53
  outputs=gr.Image(type="pil", label="Enhanced Image", format="jpeg"),
54
+ title="Professional Image Corrector",
55
+ description="Independent controls for yellow/magenta reduction with brightness preservation"
56
  )
57
 
58
  if __name__ == "__main__":