import streamlit as st import cv2 import numpy as np from PIL import Image def process_image(image, operation, rotation_angle=0, blur_value=5): img_array = np.array(image) img_cv = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR) if operation == "Greyscale": processed_img = cv2.cvtColor(img_cv, cv2.COLOR_BGR2GRAY) elif operation == "Rotate": (h, w) = img_cv.shape[:2] center = (w // 2, h // 2) M = cv2.getRotationMatrix2D(center, rotation_angle, 1.0) processed_img = cv2.warpAffine(img_cv, M, (w, h)) elif operation == "Edge Detection": processed_img = cv2.Canny(img_cv, 100, 200) elif operation == "Blur": processed_img = cv2.GaussianBlur(img_cv, (blur_value, blur_value), 0) else: processed_img = img_cv return processed_img def main(): st.title("Image Processing App") uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) if uploaded_image is not None: image = Image.open(uploaded_image) st.image(image, caption="Original Image", use_container_width=True) operation = st.selectbox("Select an operation", ["None", "Greyscale", "Rotate", "Edge Detection", "Blur"]) rotation_angle = 0 blur_value = 5 if operation == "Rotate": rotation_angle = st.slider("Select Rotation Angle", -180, 180, 0) elif operation == "Blur": blur_value = st.slider("Select Blur Intensity", 1, 25, 5, step=2) if operation != "None": processed_img = process_image(image, operation, rotation_angle, blur_value) st.image(processed_img, caption="Processed Image", use_container_width=True, channels="GRAY" if operation == "Greyscale" or operation == "Edge Detection" else "BGR") if __name__ == "__main__": main()