Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| st.title("Image to Grayscale Converter") | |
| # File uploader | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| # Load image with PIL and convert to numpy array | |
| image = Image.open(uploaded_file) | |
| image_np = np.array(image) | |
| # Convert to grayscale | |
| gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY) | |
| # Display side-by-side images | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("Original") | |
| st.image(image, width=250) | |
| with col2: | |
| st.subheader("Grayscale") | |
| st.image(gray_image, width=250, clamp=True, channels="GRAY") | |