velmurugan1122 commited on
Commit
19351de
Β·
1 Parent(s): 07e4dd9
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ def process_image(image, option, brightness_level=0, rotation_angle=0):
7
+ if option == "πŸ–€ Convert to Grayscale":
8
+ return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9
+ elif option == "🌈 Convert to Color":
10
+ return cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) if len(image.shape) == 2 else image
11
+ elif option == "πŸŒͺ️ Blur Image":
12
+ return cv2.GaussianBlur(image, (15, 15), 0)
13
+ elif option == "β˜€οΈ Increase Brightness":
14
+ hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
15
+ hsv[:, :, 2] = np.clip(hsv[:, :, 2] + brightness_level, 0, 255)
16
+ return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
17
+ elif option == "⚑ Edge Detection":
18
+ return cv2.Canny(image, 100, 200)
19
+ elif option == "πŸ”„ Rotate Image":
20
+ (h, w) = image.shape[:2]
21
+ center = (w // 2, h // 2)
22
+ matrix = cv2.getRotationMatrix2D(center, rotation_angle, 1.0)
23
+ return cv2.warpAffine(image, matrix, (w, h))
24
+ return image
25
+
26
+ st.title("πŸ“· Image Processing App")
27
+
28
+ uploaded_file = st.file_uploader("πŸ“‚ Upload an image...", type=["jpg", "png", "jpeg"])
29
+
30
+ if uploaded_file is not None:
31
+ image = np.array(Image.open(uploaded_file))
32
+
33
+ col1, col2 = st.columns(2)
34
+ with col1:
35
+ st.markdown("### 🏞️ Original Image")
36
+ st.image(image, use_container_width=True)
37
+
38
+ with col2:
39
+ st.markdown("### 🎨 Processed Image")
40
+ options = [
41
+ "πŸ–ΌοΈ Original",
42
+ "πŸ–€ Convert to Grayscale",
43
+ "🌈 Convert to Color",
44
+ "πŸ”„ Rotate Image",
45
+ "πŸŒͺ️ Blur Image",
46
+ "⚑ Edge Detection",
47
+ "β˜€οΈ Increase Brightness"
48
+ ]
49
+ selected_option = st.selectbox("πŸŽ›οΈ Select an Operation", options)
50
+
51
+ brightness_level = 0
52
+ rotation_angle = 0
53
+
54
+ if selected_option == "β˜€οΈ Increase Brightness":
55
+ brightness_level = st.slider("πŸ”† Brightness Level", -100, 100, 0)
56
+ elif selected_option == "πŸ”„ Rotate Image":
57
+ rotation_angle = st.slider("πŸŒ€ Rotation Angle", -180, 180, 0)
58
+
59
+ processed_image = process_image(image, selected_option, brightness_level, rotation_angle)
60
+
61
+ if len(processed_image.shape) == 2: # Grayscale or Edge detection
62
+ st.image(processed_image, use_container_width=True, channels="GRAY")
63
+ else:
64
+ st.image(processed_image, use_container_width=True)