File size: 1,662 Bytes
31bf833
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
from PIL import Image, ImageEnhance
import numpy as np
import cv2

# Functions for Enhancements
def enhance_image(img, brightness, contrast, sharpness, saturation):
    # Brightness
    enhancer = ImageEnhance.Brightness(img)
    img = enhancer.enhance(brightness)

    # Contrast
    enhancer = ImageEnhance.Contrast(img)
    img = enhancer.enhance(contrast)

    # Sharpness
    enhancer = ImageEnhance.Sharpness(img)
    img = enhancer.enhance(sharpness)

    # Saturation
    img_cv = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2HSV)
    img_cv[:, :, 1] = np.clip(img_cv[:, :, 1] * saturation, 0, 255)
    img = Image.fromarray(cv2.cvtColor(img_cv, cv2.COLOR_HSV2RGB))
    
    return img

# Gradio Interface
def process_image(image, brightness, contrast, sharpness, saturation):
    return enhance_image(image, brightness, contrast, sharpness, saturation)

# Gradio Inputs and Outputs
inputs = [
    gr.Image(type="pil", label="Upload an Image"),
    gr.Slider(0.5, 3.0, 1.0, label="Brightness"),
    gr.Slider(0.5, 3.0, 1.0, label="Contrast"),
    gr.Slider(0.5, 3.0, 1.0, label="Sharpness"),
    gr.Slider(0.5, 3.0, 1.0, label="Saturation"),
]

outputs = gr.Image(type="pil", label="Enhanced Image")

# Launch Gradio App
title = "Image Enhancer App"
description = """
Enhance your images with basic filters like brightness, contrast, sharpness, and saturation.
Upload an image, adjust the sliders, and see the enhanced version!
"""

demo = gr.Interface(
    fn=process_image,
    inputs=inputs,
    outputs=outputs,
    title=title,
    description=description,
    allow_flagging="never"
)

if __name__ == "__main__":
    demo.launch()