Slender commited on
Commit
684f6b0
·
1 Parent(s): 32b3b4f
Files changed (2) hide show
  1. image_editing_app.py +96 -0
  2. requirements.txt +2 -0
image_editing_app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # for creating webapp
2
+ import cv2 # image processing
3
+ from PIL import Image, ImageEnhance
4
+ import numpy as np # to deal with arrays
5
+
6
+ def cartoonize_image(our_image):
7
+ new_img = np.array(our_image.convert('RGB'))
8
+ # mask
9
+ gray = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
10
+ gray = cv2.medianBlur(gray, 5)
11
+ edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 9)
12
+ color = cv2.bilateralFilter(new_img, 9, 300, 300)
13
+ cartoon = cv2.bitwise_and(color, color, mask=edges)
14
+
15
+ return cartoon
16
+
17
+ def cannize_image(our_image):
18
+ new_img = np.array(our_image.convert('RGB'))
19
+ img = cv2.GaussianBlur(new_img, (9, 9), 0)
20
+ canny = cv2.Canny(img, 100, 150)
21
+
22
+ return canny
23
+
24
+ def main():
25
+
26
+ st.title('Image Editing App')
27
+ st.text('Edit your images in a fast and simple way')
28
+
29
+ activities = ['Detection', 'About']
30
+ choice = st.sidebar.selectbox('Select Activity', activities)
31
+
32
+ if choice == 'Detection':
33
+ st.subheader('Face Detection')
34
+ image_file = st.file_uploader('Upload Image', type=['jpg', 'jpeg', 'png'])
35
+
36
+ if image_file is not None:
37
+ our_image = Image.open(image_file)
38
+ st.text('Original Image')
39
+ enhance_type = st.sidebar.radio('Enhance type', \
40
+ options=['Gray-scale', 'Contrast', 'Brightness', 'Blurring', 'Sharpness'])
41
+ st.sidebar.image(our_image)
42
+
43
+ if enhance_type == 'Gray-scale':
44
+ # convert image to RGB arrays
45
+ img = np.array(our_image.convert('RGB'))
46
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
47
+ st.image(gray)
48
+
49
+ elif enhance_type == 'Contrast':
50
+ rate = st.sidebar.slider('Contrast', 0.5, 6.0, 2.5)
51
+ enhancer = ImageEnhance.Contrast(our_image)
52
+ enhanced_img = enhancer.enhance(rate)
53
+ st.image(enhanced_img)
54
+
55
+ elif enhance_type == 'Brightness':
56
+ rate = st.sidebar.slider('Brightness', 0.5, 6.0, 1.5)
57
+ enhancer = ImageEnhance.Brightness(our_image)
58
+ enhanced_img = enhancer.enhance(rate)
59
+ st.image(enhanced_img)
60
+
61
+ elif enhance_type == 'Blurring':
62
+ rate = st.sidebar.slider('Blurring', 0.5, 6.0, 1.5)
63
+ blurred_img = cv2.GaussianBlur(np.array(our_image), (15, 15), rate)
64
+ st.image(blurred_img)
65
+
66
+ elif enhance_type == 'Sharpness':
67
+ rate = st.sidebar.slider('Sharpness', 0.5, 6.0, 1.5)
68
+ enhancer = ImageEnhance.Sharpness(our_image)
69
+ enhanced_img = enhancer.enhance(rate)
70
+ st.image(enhanced_img)
71
+
72
+ else:
73
+ st.image(our_image)
74
+
75
+ tasks = ['Cartoonize', 'Cannize']
76
+ feature_choice = st.sidebar.selectbox('Find features', tasks)
77
+
78
+ if st.sidebar.button('Process'):
79
+
80
+ if feature_choice == 'Cartoonize':
81
+ result_img = cartoonize_image(our_image)
82
+ st.image(result_img)
83
+
84
+ if feature_choice == 'Cannize':
85
+ result_img = cannize_image(our_image)
86
+ st.image(result_img)
87
+
88
+
89
+ if choice == 'About':
90
+ st.subheader('About the developer')
91
+ st.markdown('Built with streamlit by [Slender](https://huggingface.co/Slender)')
92
+ st.text('My name is Slender, I am computer science student with an experience of 3 years in python programming.')
93
+
94
+
95
+ if __name__ == '__main__':
96
+ main()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit==1.10.0
2
+ opencv-python==4.6.0.66