Spaces:
Runtime error
Runtime error
Commit ·
5c8661f
1
Parent(s): edc2d58
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def imagen(image):
|
| 7 |
+
print(type(image),image.dtype)
|
| 8 |
+
#image = cv2.imread(np.uint8(image))
|
| 9 |
+
print(f"Image shape: {image.shape}\nImage dtype {image.dtype}")
|
| 10 |
+
image= cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
|
| 11 |
+
grayImage = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 12 |
+
grayImage = cv2.GaussianBlur(grayImage, (3, 3), 0)
|
| 13 |
+
edgeImage = cv2.Laplacian(grayImage, -1, ksize=5)
|
| 14 |
+
edgeImage = 255 - edgeImage
|
| 15 |
+
ret, edgeImage = cv2.threshold(edgeImage, 150, 255, cv2.THRESH_BINARY)
|
| 16 |
+
edgePreservingImage = cv2.edgePreservingFilter(image, flags=2, sigma_s=50, sigma_r=0.4)
|
| 17 |
+
output = np.zeros(grayImage.shape)
|
| 18 |
+
output = cv2.bitwise_and(edgePreservingImage, edgePreservingImage, mask=edgeImage)
|
| 19 |
+
candidate = cv2.cvtColor(output,cv2.COLOR_RGB2BGR)
|
| 20 |
+
#cv2.imwrite('candidate.png',candidate)
|
| 21 |
+
return candidate
|
| 22 |
+
|
| 23 |
+
interface = gr.Interface(imagen,inputs = gr.inputs.Image(shape=(1024,1024)),outputs = "image")
|
| 24 |
+
interface.launch(share=True)
|