Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,17 @@ import numpy as np
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
-
# Function to convert image to sketch
|
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 |
return sketch
|
15 |
|
16 |
# Streamlit app layout
|
@@ -93,8 +97,11 @@ if uploaded_file is not None:
|
|
93 |
|
94 |
st.write("Converting...")
|
95 |
|
96 |
-
#
|
97 |
-
|
|
|
|
|
|
|
98 |
|
99 |
col3, col4 = st.columns(2)
|
100 |
|
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
+
# Function to convert image to sketch with darkening factor
|
8 |
+
def image_to_sketch(image, darken_factor=1.0):
|
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 darkening factor
|
16 |
+
sketch = cv2.multiply(sketch, np.array([darken_factor]))
|
17 |
+
|
18 |
return sketch
|
19 |
|
20 |
# Streamlit app layout
|
|
|
97 |
|
98 |
st.write("Converting...")
|
99 |
|
100 |
+
# Darkening factor slider
|
101 |
+
darken_factor = st.slider('Adjust Darkening Factor', 0.1, 1.0, 1.0, 0.1)
|
102 |
+
|
103 |
+
# Convert the image to a sketch with the selected darkening factor
|
104 |
+
sketch = image_to_sketch(image_np, darken_factor)
|
105 |
|
106 |
col3, col4 = st.columns(2)
|
107 |
|