File size: 725 Bytes
50f9740
 
 
 
 
 
 
93d6253
50f9740
 
 
93d6253
50f9740
 
 
93d6253
50f9740
 
93d6253
 
 
 
 
 
50f9740
93d6253
 
 
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
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")