Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,16 +4,17 @@ import numpy as np
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
-
# Function to convert image to sketch with
|
8 |
-
def image_to_sketch(image,
|
9 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
inverted_image = 255 - gray_image
|
11 |
blurred_image = cv2.GaussianBlur(inverted_image, (31, 31), 0)
|
12 |
inverted_blurred = 255 - blurred_image
|
13 |
sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
|
14 |
|
15 |
-
# Apply
|
16 |
-
|
|
|
17 |
|
18 |
return sketch
|
19 |
|
@@ -97,11 +98,11 @@ if uploaded_file is not None:
|
|
97 |
|
98 |
st.write("Converting...")
|
99 |
|
100 |
-
#
|
101 |
-
|
102 |
|
103 |
-
# Convert the image to a sketch with the selected
|
104 |
-
sketch = image_to_sketch(image_np,
|
105 |
|
106 |
col3, col4 = st.columns(2)
|
107 |
|
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
+
# Function to convert image to sketch with adjustable outline thickness
|
8 |
+
def image_to_sketch(image, kernel_size=3):
|
9 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
inverted_image = 255 - gray_image
|
11 |
blurred_image = cv2.GaussianBlur(inverted_image, (31, 31), 0)
|
12 |
inverted_blurred = 255 - blurred_image
|
13 |
sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
|
14 |
|
15 |
+
# Apply morphological operation to thicken the outlines
|
16 |
+
kernel = np.ones((kernel_size, kernel_size), np.uint8)
|
17 |
+
sketch = cv2.dilate(sketch, kernel, iterations=1)
|
18 |
|
19 |
return sketch
|
20 |
|
|
|
98 |
|
99 |
st.write("Converting...")
|
100 |
|
101 |
+
# Kernel size slider for adjusting outline thickness
|
102 |
+
kernel_size = st.slider('Adjust Outline Thickness', 1, 10, 3)
|
103 |
|
104 |
+
# Convert the image to a sketch with the selected kernel size
|
105 |
+
sketch = image_to_sketch(image_np, kernel_size)
|
106 |
|
107 |
col3, col4 = st.columns(2)
|
108 |
|