File size: 2,646 Bytes
d8a38ad
 
 
 
 
a15455d
d8a38ad
 
 
 
 
 
 
 
a15455d
 
d8a38ad
b773117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a15455d
b773117
a15455d
 
 
 
d8a38ad
b773117
 
 
 
 
 
 
 
 
 
 
 
a15455d
 
 
 
 
d8a38ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a15455d
 
 
 
 
 
b773117
a15455d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import streamlit as st
import cv2
import numpy as np
from PIL import Image

# Function to convert image to sketch
def image_to_sketch(image):
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    inverted_image = 255 - gray_image
    blurred_image = cv2.GaussianBlur(inverted_image, (21, 21), 0)
    inverted_blurred = 255 - blurred_image
    sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)
    return sketch

# Streamlit app layout
st.set_page_config(page_title="Image to Sketch Converter", page_icon="🎨", layout="centered")

# Custom CSS for heading color
st.markdown("""
    <style>
    .title {
        color: #FFA500;
        font-size: 2.5em;
        font-weight: bold;
        text-align: center;
    }
    .footer {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        background-color: #f1f1f1;
        text-align: center;
        padding: 10px;
    }
    </style>
    """, unsafe_allow_html=True)

# Title and description
st.markdown('<p class="title">🎨 Image to Sketch Converter</p>', unsafe_allow_html=True)
st.markdown("""
    Convert your images into beautiful sketches with this simple app.
    Upload an image, and get the sketch version instantly!
    """)

# Example conversions
st.subheader("Example Conversions")
col1, col2 = st.columns(2)

example_image = cv2.imread('example.jpg')  # Replace with the path to an example image
example_sketch = image_to_sketch(example_image)

with col1:
    st.image(example_image, caption='Original Image', use_column_width=True)
with col2:
    st.image(example_sketch, caption='Sketch Image', use_column_width=True)

# Sidebar for user input
st.sidebar.header("Upload Your Image")
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

# Main content
if uploaded_file is not None:
    image = np.array(Image.open(uploaded_file))
    st.image(image, caption='Uploaded Image', use_column_width=True)
    
    st.write("")
    st.write("Converting...")

    sketch = image_to_sketch(image)
    
    st.image(sketch, caption='Sketch', use_column_width=True)

    # Provide a download link for the sketch image
    im_pil = Image.fromarray(sketch)
    im_pil.save("sketch.png")
    with open("sketch.png", "rb") as file:
        btn = st.download_button(
            label="Download Sketch",
            data=file,
            file_name="sketch.png",
            mime="image/png"
        )
else:
    st.sidebar.info("Please upload an image to convert.")

# Footer
st.markdown("""
    <div class="footer">
        Made with ❤️ by MallelaPreethi
    </div>
    """, unsafe_allow_html=True)