Spaces:
Running
Running
Ezhil
commited on
Commit
·
8dc4e8e
0
Parent(s):
Initial commit
Browse files- README.md +10 -0
- app.py +49 -0
- requirements.txt +4 -0
README.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Image Processing
|
3 |
+
emoji: 🏃
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: purple
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.42.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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)
|
8 |
+
img_cv = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
|
9 |
+
|
10 |
+
if operation == "Greyscale":
|
11 |
+
processed_img = cv2.cvtColor(img_cv, cv2.COLOR_BGR2GRAY)
|
12 |
+
elif operation == "Rotate":
|
13 |
+
(h, w) = img_cv.shape[:2]
|
14 |
+
center = (w // 2, h // 2)
|
15 |
+
M = cv2.getRotationMatrix2D(center, rotation_angle, 1.0)
|
16 |
+
processed_img = cv2.warpAffine(img_cv, M, (w, h))
|
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()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
opencv-python
|
3 |
+
numpy
|
4 |
+
pillow
|