Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
st.title("🎨 Grayscale Image Converter")
|
7 |
+
|
8 |
+
# Upload image
|
9 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
10 |
+
|
11 |
+
if uploaded_file is not None:
|
12 |
+
# Read image
|
13 |
+
image = Image.open(uploaded_file)
|
14 |
+
st.image(image, caption='Original Image', use_column_width=True)
|
15 |
+
|
16 |
+
# Convert PIL image to OpenCV format
|
17 |
+
img_array = np.array(image)
|
18 |
+
if img_array.shape[2] == 4: # handle RGBA
|
19 |
+
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2RGB)
|
20 |
+
|
21 |
+
# Convert to grayscale
|
22 |
+
gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
23 |
+
|
24 |
+
# Display the grayscale image
|
25 |
+
st.image(gray_image, caption='Grayscale Image', use_column_width=True, channels="GRAY")
|