gokaygokay's picture
Update app.py
7a48a84 verified
raw
history blame
1.58 kB
import cv2
import numpy as np
from numba import jit, prange
import gradio as gr
@jit(nopython=True, parallel=True)
def fast_poisson_sharpening(img, alpha):
img_h, img_w = img.shape
output = np.zeros_like(img)
for y in prange(1, img_h - 1):
for x in range(1, img_w - 1):
laplacian = (
img[y-1, x] + img[y+1, x] + img[y, x-1] + img[y, x+1] - 4 * img[y, x]
)
output[y, x] = img[y, x] + alpha * laplacian
return np.clip(output, 0, 1)
def sharpen_image(input_img, alpha):
# Convert BGR to RGB
img = cv2.cvtColor(input_img, cv2.COLOR_BGR2RGB).astype('float32') / 255.0
sharpen_img = np.zeros_like(img)
for b in range(3):
sharpen_img[:,:,b] = fast_poisson_sharpening(img[:,:,b], alpha)
# Convert back to BGR for output
return cv2.cvtColor((sharpen_img * 255).astype(np.uint8), cv2.COLOR_RGB2BGR)
# Create examples list
examples = [
["img1.jpg", 0.5],
["img2.PNG", 0.3],
]
# Create the Gradio interface
iface = gr.Interface(
fn=sharpen_image,
inputs=[
gr.Image(label="Input Image", type="numpy"),
gr.Slider(minimum=0.1, maximum=1.0, step=0.01, value=0.5, label="Sharpening Strength (alpha)")
],
outputs=gr.Image(label="Sharpened Image"),
title="Fast Poisson Image Sharpening",
description="Upload an image or choose from the examples, then adjust the sharpening strength to enhance edges and details.",
theme='bethecloud/storj_theme',
examples=examples,
cache_examples=True
)
iface.launch()