Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
| 9 |
+
|
| 10 |
+
if uploaded_file is not None:
|
| 11 |
+
# Load image using PIL and convert to numpy array
|
| 12 |
+
image = Image.open(uploaded_file)
|
| 13 |
+
img_array = np.array(image)
|
| 14 |
+
|
| 15 |
+
# Convert to grayscale using OpenCV
|
| 16 |
+
gray_img = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 17 |
+
|
| 18 |
+
# Convert back to image format for display
|
| 19 |
+
st.image(gray_img, caption="Grayscale Image", use_column_width=True, clamp=True)
|