Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| st.title("π¨ Grayscale Image Converter") | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file) | |
| # Convert PIL to OpenCV format | |
| img_array = np.array(image) | |
| if img_array.shape[2] == 4: | |
| img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2RGB) | |
| gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY) | |
| # Display side-by-side in smaller size | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.image(image, caption="Original", width=250) | |
| with col2: | |
| st.image(gray_image, caption="Grayscale", width=250, channels="GRAY") | |