Spaces:
Sleeping
Sleeping
File size: 736 Bytes
e59e28f 14f21f2 e59e28f 14f21f2 e59e28f 14f21f2 |
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 |
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")
|