Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,21 +4,21 @@ import numpy as np
|
|
4 |
from PIL import Image
|
5 |
|
6 |
# Function to convert image to sketch
|
7 |
-
def convert_to_sketch(image):
|
8 |
# Convert image to grayscale
|
9 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
|
11 |
# Invert the grayscale image
|
12 |
inverted_gray_image = 255 - gray_image
|
13 |
|
14 |
-
# Apply Gaussian Blur
|
15 |
-
blurred_image = cv2.GaussianBlur(inverted_gray_image, (
|
16 |
|
17 |
# Invert the blurred image
|
18 |
inverted_blurred_image = 255 - blurred_image
|
19 |
|
20 |
-
# Create the pencil sketch image
|
21 |
-
sketch_image = cv2.divide(gray_image, inverted_blurred_image, scale=
|
22 |
|
23 |
return sketch_image
|
24 |
|
@@ -33,13 +33,18 @@ st.image(logo_url, width=200) # Adjust the width as needed
|
|
33 |
# Upload image - allow all image formats
|
34 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"])
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
if uploaded_file is not None:
|
37 |
# Read the image
|
38 |
image = Image.open(uploaded_file)
|
39 |
image = np.array(image)
|
40 |
|
41 |
-
# Convert the image to sketch
|
42 |
-
sketch_image = convert_to_sketch(image)
|
43 |
|
44 |
# Display the original image
|
45 |
st.image(image, caption='Original Image', use_column_width=True)
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
# Function to convert image to sketch
|
7 |
+
def convert_to_sketch(image, blur_intensity, sketch_intensity):
|
8 |
# Convert image to grayscale
|
9 |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
|
11 |
# Invert the grayscale image
|
12 |
inverted_gray_image = 255 - gray_image
|
13 |
|
14 |
+
# Apply Gaussian Blur with adjustable intensity
|
15 |
+
blurred_image = cv2.GaussianBlur(inverted_gray_image, (blur_intensity, blur_intensity), 0)
|
16 |
|
17 |
# Invert the blurred image
|
18 |
inverted_blurred_image = 255 - blurred_image
|
19 |
|
20 |
+
# Create the pencil sketch image with adjustable intensity
|
21 |
+
sketch_image = cv2.divide(gray_image, inverted_blurred_image, scale=sketch_intensity)
|
22 |
|
23 |
return sketch_image
|
24 |
|
|
|
33 |
# Upload image - allow all image formats
|
34 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"])
|
35 |
|
36 |
+
# Add settings in the sidebar
|
37 |
+
st.sidebar.title("Settings")
|
38 |
+
blur_intensity = st.sidebar.slider("Blur Intensity", min_value=1, max_value=99, value=21, step=2)
|
39 |
+
sketch_intensity = st.sidebar.slider("Sketch Intensity", min_value=100, max_value=300, value=256, step=10)
|
40 |
+
|
41 |
if uploaded_file is not None:
|
42 |
# Read the image
|
43 |
image = Image.open(uploaded_file)
|
44 |
image = np.array(image)
|
45 |
|
46 |
+
# Convert the image to sketch using the selected settings
|
47 |
+
sketch_image = convert_to_sketch(image, blur_intensity, sketch_intensity)
|
48 |
|
49 |
# Display the original image
|
50 |
st.image(image, caption='Original Image', use_column_width=True)
|