|
import numpy as np |
|
import gradio as gr |
|
import cv2 |
|
|
|
|
|
def enhance(input_img, brightness): |
|
|
|
input_img = input_img.astype(np.float32) / 255.0 |
|
|
|
|
|
sharpen_filter = np.array([ |
|
[0, -1, 0], |
|
[-1, 5, -1], |
|
[0, -1, 0] |
|
]) |
|
|
|
|
|
sharpened_img = cv2.filter2D(input_img, -1, sharpen_filter) |
|
|
|
|
|
smoothed_img = cv2.GaussianBlur(sharpened_img, (3, 3), 0) |
|
|
|
|
|
smoothed_img = np.clip(smoothed_img + brightness, 0, 1) |
|
|
|
|
|
smoothed_img = smoothed_img / smoothed_img.max() |
|
|
|
|
|
smoothed_img = (smoothed_img * 255).astype(np.uint8) |
|
|
|
return smoothed_img |
|
|
|
|
|
demo = gr.Interface( |
|
enhance, |
|
inputs=[gr.Image(), gr.Slider(-1.0, 1.0, value=0.0, label="Brightness")], |
|
outputs="image" |
|
) |
|
|
|
|
|
demo.launch(show_error=True) |