Commit
Β·
19351de
1
Parent(s):
07e4dd9
ui fix
Browse files
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)
|