File size: 2,514 Bytes
19351de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)