Ezhil commited on
Commit
a4d712e
Β·
1 Parent(s): 8dc4e8e

edit the app code

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import cv2
3
  import numpy as np
4
  from PIL import Image
 
5
 
6
  def process_image(image, operation, rotation_angle=0, blur_value=5):
7
  img_array = np.array(image)
@@ -17,33 +18,55 @@ def process_image(image, operation, rotation_angle=0, blur_value=5):
17
  elif operation == "Edge Detection":
18
  processed_img = cv2.Canny(img_cv, 100, 200)
19
  elif operation == "Blur":
20
- processed_img = cv2.GaussianBlur(img_cv, (blur_value, blur_value), 0)
21
  else:
22
  processed_img = img_cv
23
 
24
  return processed_img
25
 
26
  def main():
27
- st.title("Image Processing App")
28
- uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
 
 
29
 
30
  if uploaded_image is not None:
31
  image = Image.open(uploaded_image)
32
- st.image(image, caption="Original Image", use_container_width=True)
33
 
34
- operation = st.selectbox("Select an operation", ["None", "Greyscale", "Rotate", "Edge Detection", "Blur"])
 
 
 
 
35
 
36
  rotation_angle = 0
37
  blur_value = 5
38
 
39
  if operation == "Rotate":
40
- rotation_angle = st.slider("Select Rotation Angle", -180, 180, 0)
 
41
  elif operation == "Blur":
42
- blur_value = st.slider("Select Blur Intensity", 1, 25, 5, step=2)
 
 
 
 
 
 
43
 
44
  if operation != "None":
45
  processed_img = process_image(image, operation, rotation_angle, blur_value)
46
- st.image(processed_img, caption="Processed Image", use_container_width=True, channels="GRAY" if operation == "Greyscale" or operation == "Edge Detection" else "BGR")
 
 
 
 
 
 
 
 
 
 
47
 
48
  if __name__ == "__main__":
49
  main()
 
2
  import cv2
3
  import numpy as np
4
  from PIL import Image
5
+ import io
6
 
7
  def process_image(image, operation, rotation_angle=0, blur_value=5):
8
  img_array = np.array(image)
 
18
  elif operation == "Edge Detection":
19
  processed_img = cv2.Canny(img_cv, 100, 200)
20
  elif operation == "Blur":
21
+ processed_img = cv2.GaussianBlur(img_cv, (blur_value*2+1, blur_value*2+1), 0)
22
  else:
23
  processed_img = img_cv
24
 
25
  return processed_img
26
 
27
  def main():
28
+ st.title("πŸ–ΌοΈ Image Processing App 🎨")
29
+ st.markdown("Enhance your images with various effects!")
30
+
31
+ uploaded_image = st.file_uploader("πŸ“€ Upload an image", type=["jpg", "png", "jpeg"])
32
 
33
  if uploaded_image is not None:
34
  image = Image.open(uploaded_image)
 
35
 
36
+ st.markdown("### ✏️ Editing Options")
37
+ col3, col4 = st.columns(2)
38
+
39
+ with col3:
40
+ operation = st.selectbox("πŸ”§ Select an operation", ["None", "Greyscale", "Rotate", "Edge Detection", "Blur"])
41
 
42
  rotation_angle = 0
43
  blur_value = 5
44
 
45
  if operation == "Rotate":
46
+ with col4:
47
+ rotation_angle = st.slider("πŸ”„ Rotation Angle", -180, 180, 0)
48
  elif operation == "Blur":
49
+ with col4:
50
+ blur_value = st.slider("🌫️ Blur Intensity", 1, 25, 5, step=2)
51
+
52
+ col1, col2 = st.columns(2)
53
+
54
+ with col1:
55
+ st.image(image, caption="πŸ–ΌοΈ Original Image", use_container_width=True)
56
 
57
  if operation != "None":
58
  processed_img = process_image(image, operation, rotation_angle, blur_value)
59
+
60
+ with col2:
61
+ st.image(processed_img, caption="✨ Processed Image", use_container_width=True, channels="GRAY" if operation == "Greyscale" or operation == "Edge Detection" else "BGR")
62
+
63
+ processed_pil = Image.fromarray(cv2.cvtColor(processed_img, cv2.COLOR_BGR2RGB) if operation != "Greyscale" and operation != "Edge Detection" else processed_img)
64
+ buf = io.BytesIO()
65
+ processed_pil.save(buf, format="PNG")
66
+ byte_im = buf.getvalue()
67
+
68
+ st.markdown("### πŸ“₯ Download Your Edited Image")
69
+ st.download_button(label="πŸ’Ύ Download", data=byte_im, file_name="processed_image.png", mime="image/png")
70
 
71
  if __name__ == "__main__":
72
  main()