File size: 1,248 Bytes
55ac840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import gradio as gr
import cv2

# Define a function to apply a more aesthetically pleasing sharpening filter to an image
def enhance(input_img, brightness):
    # Convert the image to float32 for better precision
    input_img = input_img.astype(np.float32) / 255.0
    
    # Define a more subtle sharpening filter
    sharpen_filter = np.array([
        [0, -1, 0],
        [-1, 5, -1],
        [0, -1, 0]
    ])
    
    # Apply the filter to the image
    sharpened_img = cv2.filter2D(input_img, -1, sharpen_filter)
    
    # Apply a slight Gaussian blur to smooth out the sharpening effect
    smoothed_img = cv2.GaussianBlur(sharpened_img, (3, 3), 0)
    
    # Adjust brightness
    smoothed_img = np.clip(smoothed_img + brightness, 0, 1)
    
    # Normalize the image to the range [0, 1]
    smoothed_img = smoothed_img / smoothed_img.max()
    
    # Convert back to uint8 for display
    smoothed_img = (smoothed_img * 255).astype(np.uint8)
    
    return smoothed_img

# Create a Gradio interface for the enhancement function
demo = gr.Interface(
    enhance, 
    inputs=[gr.Image(), gr.Slider(-1.0, 1.0, value=0.0, label="Brightness")], 
    outputs="image"
)

# Launch the Gradio app
demo.launch(show_error=True)