Spaces:
Running
Running
Ezhil
commited on
Commit
Β·
a4d712e
1
Parent(s):
8dc4e8e
edit the app code
Browse files
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 |
-
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
rotation_angle = 0
|
37 |
blur_value = 5
|
38 |
|
39 |
if operation == "Rotate":
|
40 |
-
|
|
|
41 |
elif operation == "Blur":
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
if operation != "None":
|
45 |
processed_img = process_image(image, operation, rotation_angle, blur_value)
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|