import streamlit as st import cv2 import numpy as np from PIL import Image def process_image(image, option, brightness_level=0, rotation_angle=0): if option == "🖤 Convert to Grayscale": return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) elif option == "🌈 Convert to Color": return cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) if len(image.shape) == 2 else image elif option == "🌪️ Blur Image": return cv2.GaussianBlur(image, (15, 15), 0) elif option == "☀️ Increase Brightness": hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) hsv[:, :, 2] = np.clip(hsv[:, :, 2] + brightness_level, 0, 255) return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) elif option == "⚡ Edge Detection": return cv2.Canny(image, 100, 200) elif option == "🔄 Rotate Image": (h, w) = image.shape[:2] center = (w // 2, h // 2) matrix = cv2.getRotationMatrix2D(center, rotation_angle, 1.0) return cv2.warpAffine(image, matrix, (w, h)) return image st.title("📷 Image Processing App") uploaded_file = st.file_uploader("📂 Upload an image...", type=["jpg", "png", "jpeg"]) if uploaded_file is not None: image = np.array(Image.open(uploaded_file)) col1, col2 = st.columns(2) with col1: st.markdown("### 🏞️ Original Image") st.image(image, use_container_width=True) with col2: st.markdown("### 🎨 Processed Image") options = [ "🖼️ Original", "🖤 Convert to Grayscale", "🌈 Convert to Color", "🔄 Rotate Image", "🌪️ Blur Image", "⚡ Edge Detection", "☀️ Increase Brightness" ] selected_option = st.selectbox("🎛️ Select an Operation", options) brightness_level = 0 rotation_angle = 0 if selected_option == "☀️ Increase Brightness": brightness_level = st.slider("🔆 Brightness Level", -100, 100, 0) elif selected_option == "🔄 Rotate Image": rotation_angle = st.slider("🌀 Rotation Angle", -180, 180, 0) processed_image = process_image(image, selected_option, brightness_level, rotation_angle) if len(processed_image.shape) == 2: # Grayscale or Edge detection st.image(processed_image, use_container_width=True, channels="GRAY") else: st.image(processed_image, use_container_width=True)