File size: 1,589 Bytes
3f4b254
525a687
3f4b254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a93abe5
3f4b254
 
 
 
 
 
a93abe5
 
3f4b254
 
 
 
 
a93abe5
 
3f4b254
 
 
 
 
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
import streamlit as st
import cv2
import numpy as np
from PIL import Image

st.title("📸Image Processing App")

# Upload image
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    
    # Convert PIL image to OpenCV format
    img_array = np.array(image)

    # Show original image
    st.subheader("Original vs Processed Image")
    col1, col2 = st.columns(2)

    with col1:
        st.image(image, caption="Original Image", use_container_width=True)

    processed_image = img_array  # Initialize processed_image with original image

    # Convert to Grayscale
    if st.button("Convert to Grayscale"):
        processed_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
    
    # Rotate Image
    angle = st.slider("Select Rotation Angle", -180, 180, 0)
    if st.button("Rotate Image"):
        (h, w) = img_array.shape[:2]
        center = (w // 2, h // 2)
        matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
        processed_image = cv2.warpAffine(img_array, matrix, (w, h))
    
    # Add Text Overlay
    text = st.text_input("Enter text to overlay on the image", "Hello")
    if st.button("Apply Text Overlay"):
        image_copy = img_array.copy()
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(image_copy, text, (50, 50), font, 1, (255, 0, 0), 2, cv2.LINE_AA)
        processed_image = image_copy

    # Show processed image in the second column
    with col2:
        st.image(processed_image, caption="Processed Image", use_container_width=True)