Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,39 +2,30 @@ import gradio as gr
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
-
import io
|
6 |
|
7 |
def convert_to_sketch(image):
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
pil_image = Image.fromarray(sketch)
|
27 |
-
|
28 |
-
# Menyimpan gambar dalam format JPG
|
29 |
-
img_byte_arr = io.BytesIO()
|
30 |
-
pil_image.save(img_byte_arr, format="JPEG")
|
31 |
-
img_byte_arr.seek(0) # Kembali ke awal stream
|
32 |
-
|
33 |
-
return img_byte_arr # Gradio akan menangani ini sebagai file gambar
|
34 |
|
35 |
-
#
|
36 |
gr.Interface(fn=convert_to_sketch,
|
37 |
inputs="image",
|
38 |
-
outputs=
|
39 |
title="Konversi gambar ke sketsa",
|
40 |
-
description="Unggah gambar dan dapatkan versi sketsa
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
|
|
5 |
|
6 |
def convert_to_sketch(image):
|
7 |
+
img = np.array(image)
|
8 |
|
9 |
+
#ubah gambar ke grayscale
|
10 |
+
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
11 |
|
12 |
+
#inversi warna
|
13 |
+
inverted_image = cv2.bitwise_not(gray_image)
|
14 |
|
15 |
+
#terapkan gaussian blur
|
16 |
+
blurred = cv2.GaussianBlur(inverted_image, (21, 21), sigmaX=0, sigmaY=0)
|
17 |
|
18 |
+
#inversi hasil blur
|
19 |
+
inverted_blurred = cv2.bitwise_not(blurred)
|
20 |
|
21 |
+
#buat sketsa
|
22 |
+
sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
|
23 |
|
24 |
+
return sketch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
#interface
|
27 |
gr.Interface(fn=convert_to_sketch,
|
28 |
inputs="image",
|
29 |
+
outputs="image",
|
30 |
title="Konversi gambar ke sketsa",
|
31 |
+
description="Unggah gambar dan dapatkan versi sketsa").launch()
|