Spaces:
Sleeping
Sleeping
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) |