File size: 3,551 Bytes
684f6b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
import streamlit as st # for creating webapp
import cv2 # image processing
from PIL import Image, ImageEnhance
import numpy as np # to deal with arrays

def cartoonize_image(our_image):
    new_img = np.array(our_image.convert('RGB'))
    # mask
    gray = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
    gray = cv2.medianBlur(gray, 5)
    edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 9)
    color = cv2.bilateralFilter(new_img, 9, 300, 300)
    cartoon = cv2.bitwise_and(color, color, mask=edges)

    return cartoon

def cannize_image(our_image):
    new_img = np.array(our_image.convert('RGB'))
    img = cv2.GaussianBlur(new_img, (9, 9), 0)
    canny = cv2.Canny(img, 100, 150)

    return canny

def main():

    st.title('Image Editing App')
    st.text('Edit your images in a fast and simple way')

    activities = ['Detection', 'About']
    choice = st.sidebar.selectbox('Select Activity', activities)

    if choice == 'Detection':
        st.subheader('Face Detection')
        image_file = st.file_uploader('Upload Image', type=['jpg', 'jpeg', 'png'])

        if image_file is not None:
            our_image = Image.open(image_file)
            st.text('Original Image')
            enhance_type = st.sidebar.radio('Enhance type', \
                                            options=['Gray-scale', 'Contrast', 'Brightness', 'Blurring', 'Sharpness'])
            st.sidebar.image(our_image)

            if enhance_type == 'Gray-scale':
                # convert image to RGB arrays
                img = np.array(our_image.convert('RGB'))
                gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                st.image(gray)

            elif enhance_type == 'Contrast':
                rate = st.sidebar.slider('Contrast', 0.5, 6.0, 2.5)
                enhancer = ImageEnhance.Contrast(our_image)
                enhanced_img = enhancer.enhance(rate)
                st.image(enhanced_img)

            elif enhance_type == 'Brightness':
                rate = st.sidebar.slider('Brightness', 0.5, 6.0, 1.5)
                enhancer = ImageEnhance.Brightness(our_image)
                enhanced_img = enhancer.enhance(rate)
                st.image(enhanced_img)

            elif enhance_type == 'Blurring':
                rate = st.sidebar.slider('Blurring', 0.5, 6.0, 1.5)
                blurred_img = cv2.GaussianBlur(np.array(our_image), (15, 15), rate)
                st.image(blurred_img)

            elif enhance_type == 'Sharpness':
                rate = st.sidebar.slider('Sharpness', 0.5, 6.0, 1.5)
                enhancer = ImageEnhance.Sharpness(our_image)
                enhanced_img = enhancer.enhance(rate)
                st.image(enhanced_img)

            else:
                st.image(our_image)

        tasks = ['Cartoonize', 'Cannize']
        feature_choice = st.sidebar.selectbox('Find features', tasks)

        if st.sidebar.button('Process'):

            if feature_choice == 'Cartoonize':
                result_img = cartoonize_image(our_image)
                st.image(result_img)

            if feature_choice == 'Cannize':
                result_img = cannize_image(our_image)
                st.image(result_img)


    if choice == 'About':
        st.subheader('About the developer')
        st.markdown('Built with streamlit by [Slender](https://huggingface.co/Slender)')
        st.text('My name is Slender, I am computer science student with an experience of 3 years in python programming.')


if __name__ == '__main__':
    main()