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)