| 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: |
| st.image(processed_image, use_container_width=True, channels="GRAY") |
| else: |
| st.image(processed_image, use_container_width=True) |
|
|